Re: Boolean access in multithreaded environment

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

From: Chris Tacke, eMVP (ctacke[at]Open_NET_CF[dot]org)
Date: 05/21/04


Date: Fri, 21 May 2004 07:56:35 -0400

The CF doesn't support volatile, but I'd use a sych feature like a lock or
mutex to make sure that writes and reads don't step on one another, atomic
or not. That simply good coding practice.

-Chris

<ManojM> wrote in message news:OEczsOyPEHA.1644@TK2MSFTNGP09.phx.gbl...
> 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: When is "volatile" used instead of "lock" ?
    ... I've been trying to get to your assertion of no JIT optimizations of members ... between Enter/Exit because of "volatility guarantees" in the CLI spec. ... between Enter/Exit were considered volatile operations-which is probably why ... publicly visible object is used as the lock object, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: 2 different threads checking on same variable scenario
    ... If the sharedVar is a boolean, you don't need any kind of lock. ... unless sharedVar is declared to be volatile. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: When is "volatile" used instead of "lock" ?
    ... "lock" cannot not apply. ... > synchronized method) shall implicitly perform a volatile write ... reference used as the parameter for the lock. ... There can be no lock acquire semantics for value members. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: When is "volatile" used instead of "lock" ?
    ... The sample clearly shows that putting a member between Enter/Exit does not ... Within Enter/Exit, if there are no other volatile operations involved, ... If A acquired a lock and D releases it, ...
    (microsoft.public.dotnet.languages.csharp)
  • 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)