Link to home
Start Free TrialLog in
Avatar of bichito
bichito

asked on

Pointers to functions and concurrency

I want to confirm my suspicion (I am working under RH 7.3):

I have a struct of type SomeType that has as a member a pointer to a function F (stateless function)

I can do the following:

SomeType ST1;

SomeType ST2;

// initialization code, etc

call to function F through ST1
call to function F through ST2
.
.
.

without worrying about ST1 and ST2 accessing the function. But what about if ST1 and ST2 were in different threads (LWP)?

Do I need to add protection to those calls?


ASKER CERTIFIED SOLUTION
Avatar of frogger1999
frogger1999

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bichito
bichito

ASKER

You are right.

This will boil down to to implementation of pthreads and it is not dependent on C itself.

All my variables are in the stack or are parameters. These "should" be thread specific.

I will need to dig into pthreads to verify this.

How do I award the points?
Avatar of bichito

ASKER

FYI, if anybody has the same doubt:

The pthreads specs specifies a stack per thread.

So as long as the variables in the function pointed to are in the stack there is no need for protection