Boost logo

Boost Users :

Subject: Re: [Boost-users] [Thread] How to invoke a memory fence?
From: Anthony Williams (anthony.ajw_at_[hidden])
Date: 2009-01-28 05:45:00


"Radosavljevic, Branko" <branko.radosavljevic_at_[hidden]>
writes:

> I have a newbie question about using Boost.Thread to invoke a memory
> fence operation. What are the memory fence guarantees associated
> with the synchronization concepts in Boost.Thread?
>
> My specific use case involves one writer and several readers.
> For example, something like:
>
> bool available = false;
> int value;
>
> // Writer thread
> value = getValue();
> available = true;
>
> // A reader thread
> while (!available)
> yield();
> doSomething(value);
>
> In other words, the write to available should have release
> semantics, and the read from available should have acquire
> semantics. I realize I can use platform-specific commands,
> but I'd rather not. I assume that if I want to use Boost.Thread,
> I'll need to use a mutex, but I don't see any discussion
> of memory fence issues in the documentation.

If you use a mutex to protect "available", then the appropriate
semantics will be in place.

Anthony

-- 
Anthony Williams
Author of C++ Concurrency in Action | http://www.manning.com/williams
just::thread C++0x thread library   | http://www.stdthread.co.uk
Custom Software Development         | http://www.justsoftwaresolutions.co.uk
Just Software Solutions Ltd, Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net