Link to home
Start Free TrialLog in
Avatar of schneiderit
schneideritFlag for United Kingdom of Great Britain and Northern Ireland

asked on

lock on bool when access via multiple threads

Guys,

I have two threads.  

Currently I check on a bool to determine whether one of the threads should stop work.  The bool is set from the other thread.  Do I need to lock around the bool?  I presumed I would, but collegues believe I may not have to? Another collegue mentioned setting the bool to volatile, so it's not cached?  I appreciate if anyone could suggest the correct action.

Thanks.

- Lee.

Avatar of itsmeandnobodyelse
itsmeandnobodyelse
Flag of Germany image

>>>> Do I need to lock around the bool?
You only need to lock if both threads were updating the bool. If only one is writing and the other is only reading, the lock is not needed.
ASKER CERTIFIED SOLUTION
Avatar of itsmeandnobodyelse
itsmeandnobodyelse
Flag of Germany image

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 schneiderit

ASKER

that's great, thankyou.