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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Static Data over multiple threads

Status
Not open for further replies.

RichardF

Programmer
Oct 9, 2000
239
GB
Hi,

my app has 2 threads both which access the same static data (in a struct). I am aware that either thread could change one of these variables which obviously is a problem.

does anyone have an opinion on this method - or can see furthur problems ?

thanks in advance
Rich
 
Yes, is nor problem. Only problem is in synchronization.

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Ion is correct of course [lol]

Wrap all writing to variables in a CRITICAL_SECTION. See the MSDN SDK for details of how to do that, start at the InitializeCriticalSection() API.

-pete
 
Thanks,

Just out of interest - is there a difference between using mutex objects and using critial sections ?

Rich.
 
Yes,
mutex will sinchronize any instances of programs(processes) but critical section only threads inside a single instance a program(process)

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top