Jump to content

pthread safe library functions?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
mynickmynick

mynickmynick

    Newbie

  • Members
  • PipPip
  • 11 posts
In linux using pthreads
When I call a whatever usual function (like div() sin() exp() pow() rand() nanosleep() etc.) in the following way:

thread 1
a=div(b,c).rem

thread 2
x=div(y,z).rem

so I call the same function on different (not shared) data
Can I be sure that the two function calls by the two threads do not share any (internal) data (may be registers or global-library-shared) and so have no side unpredicted effect??

#2
G_Morgan

G_Morgan

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 537 posts
Threads have a different register and stack context by definition. As long as you aren't sharing any memory it should be fine.

#3
mynickmynick

mynickmynick

    Newbie

  • Members
  • PipPip
  • 11 posts
ok thanks but can I be sure that these "standard-or-usual external libraries functions" when called by different threads do not share global variables (non stack variables) on their own ??

#4
G_Morgan

G_Morgan

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 537 posts
Not without viewing the source code but It's unlikely.