|
Boost : |
From: Gottlob Frege (gottlobfrege_at_[hidden])
Date: 2007-04-19 12:39:22
On 4/19/07, Dmitriy V'jukov <dvyukov_at_[hidden]> wrote:
> Peter Dimov wrote:
>
> > There's also a hidden ordinary store to the vtable pointer. In general,
> when
> > passing an object X from thread A to thread B, you are expected to ensure
> > the necessary visibility (and not the author of X). Usually the queue that
>
> > you're using for message passing will contain the acquire/release pair in
> > pop/push. Otherwise you wouldn't be able to pass ordinary objects between
> > threads. Or to take a simple example:
>
>
> Thank you very much. Now I understand.
> I underestimate the "pass to another thread" procedure, that must contain
> all necessary fences to ensure visibility of counter variable.
>
In particular, looking at your original example:
> shared_count volatile* sc;
>
> void thread1()
> {
> //...
> sc = new shared_count();
*** need a write barrier here,
so that other thread doesn't see 'sc' set before its contents ***
> //...
> }
>
> void thread2()
> {
> //...
*** need a read barrier when reading 'sc',
so that you don't see it before its contents ***
> while (!sc) Sleep(1);
> sc->inc();
> if (!sc->dec()) delete sc;
> //...
> }
>
Tony
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk