Boolean access in multithreaded environment

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

ManojM
Date: 05/21/04


Date: Fri, 21 May 2004 16:36:08 +0530

Hi
I have one thread assigning true/false to boolean and another thread
accessing the value of the boolean. I need this operation to be thread safe.
Someone told me that boolean assignment is atomic operation and thats why I
need not make it volatile. Is it true that its atomic or should I make it
volatile/restrict its access by lock?

Thanks
Manoj



Relevant Pages

  • Re: Boolean access in multithreaded environment
    ... > I have one thread assigning true/false to boolean and another thread ... > accessing the value of the boolean. ... > need not make it volatile. ... > volatile/restrict its access by lock? ...
    (microsoft.public.pocketpc.developer)
  • Re: Boolean access in multithreaded environment
    ... > accessing the value of the boolean. ... > Someone told me that boolean assignment is atomic operation and thats why ... > need not make it volatile. ... > volatile/restrict its access by lock? ...
    (microsoft.public.pocketpc.developer)
  • Re: do I need "volatile" for HashMap? when I apply ReentrantReadWriteLock on it.
    ... ReentrantReadWriteLock rwl = new ReentrantReadWriteLock; ... Using volatile here makes sense to me. ... In either case if your boolean were used in a synchronized block or as in this case a locked section of code it would not need it's own synchronization to make changes in other threads visible. ...
    (comp.lang.java.programmer)
  • Re: boolean and thread safety
    ... One byte could be in memory while a different thread could have that same byte in cache or in a register. ... Anything else requires more explicit synchronization. ... For this specific example you probably want to declare your boolean as volatile. ...
    (comp.lang.java.programmer)