>>My question is whether I need to use locks around
Yes, you need to synchronize access to that variable. There are a couple ways to do it: 1) semiphores, and 2) critical sections. Years ago I didn't do either because all it did was increment a global varialble. It cost me three days to figure out why my program randomily froze -- it was in a deadlock situation.
I would suggest you write a function to increment the variable. Inside that function you can add code to synchronize the threads. Then call that function instead of incrementing the variable all over the code.
Last edited by Ancient Dragon; Sep 7th, 2009 at 1:11 am.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Offline 21,949 posts
since Aug 2005