Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multi threading and Global variables.

Status
Not open for further replies.

kathyayini

Programmer
Aug 16, 2002
52
0
0
IN
I have 10 global variables (the purpose of making it global is that all the variables are used in different functions). I am using multithreading and i do not want interaction between the threads. is there is a way to make threads to treat all global variables as local. what i mean to say is when i execute 2 thread at the same time, the global variables get manipulated by both the threads.
 
if you use HPUX cc/aCC you can declare global variables as thread-specific with the '__thread' C keyword. i dont know if that is supported in other platforms. but there is the posxi standard thread API pthread_setspecific to make data thread-spefific. you can read the man page and get more info.
 
Is this only C code - because if you have C++ compiler I would highly recommend the use of functionoids in such a scenario.

Do let me know if you need more info on how to use functionoid's with multithreading...provided ofcourse you are using a C++ & not a C compiler

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top