Re: [OT]Re: atomic flag
From: Nick Hounsome (nh002_at_blueyonder.co.uk)
Date: 01/15/04
- Next message: Nick Hounsome: "Re: i/o Fortran's format commands in c++"
- Previous message: dullboy: "linker errors: LNK2005"
- In reply to: Jeff Schwab: "Re: [OT]Re: atomic flag"
- Next in thread: Jeff Schwab: "Re: [OT]Re: atomic flag"
- Reply: Jeff Schwab: "Re: [OT]Re: atomic flag"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 15 Jan 2004 06:21:52 -0000
"Jeff Schwab" <jeffplus@comcast.net> wrote in message
news:R7Wdnca8e_HIcpjdRVn-jw@comcast.com...
> Ron Natalie wrote:
> > "Jeff Schwab" <jeffplus@comcast.net> wrote in message
news:27idncgNDfwefZjdRVn-uQ@comcast.com...
> >
> >>Peter Koch Larsen wrote:
> >>
> >>>"Jeff Schwab" <jeffplus@comcast.net> skrev i en meddelelse
> >>>news:886dnfBKB6Y_y5nd4p2dnA@comcast.com...
> >>>
> >>>
> >>>>Shayan wrote:
> >>>>
> >>>>
> >>>>>Is there a boolean flag that can be set atomically without needing to
> >>>>>wrap it in a mutex? This flag will be checked constantly by multiple
> >>>>>threads so I don't really want to deal with the overhead of mutexes
or
> >>>>>semaphores. Thanks.
> >>>>
> >>>>
> >>>>I believe setting a flag /is/ an atomic action. It's when you want to
> >>>>bundle multiple operations as an atom that problems may occur
> >>>>
> >>>
> >>>You are wrong - at least on systems with multiple processors.
> >>
> >>No, I'm not. The machines I use most have from two to fourteen
> >>processors. All the processors on a given machine share some memory.
> >>
> >
> >
> > That doesn't say anything about automic operations.
>
> Yes, it does. The memory -- the place where the datum is stored -- is
> shared among the processors. A write is atomic.
>
> > More is involved then
> > just sharing memory. Do these things have cache? It's extremely rare
to
> > see a machine the memory itself is synchronized (the HEP was unique in
> > this regard).
>
> Keeping the cache in sync with the memory is done at a much lower level.
> It's the concern of the hardware & the OS.
>
I'm with Ron on this one:
The memory can't be kept totally in sync in the way that I think is being
discussed here -
think about it - it would hammer performance.
The OS helps but only at certain points which means that you have to use
things like mutexes for memory shared between
processors. The locking and unlocking of the mutexes consitute 'memory
barriers'
Locking the mutex throws out cached reads so that you get any new stuff in
the memory.
Unlocking the mutex flushes out cached writes.
Obviously it is possible to have an machine code instruction that does the
whole lot - that is how mutexes in shared memory are written.
Anyway the original poster seemed to want:
volatile bool* flag;
while(flag)
;
flag = true;
This is unlikely to work even on a single processor machine.
Getting back to C++ - I think I read somewhere that there is a clash between
C++ and the POSIX threads decls but
I have never had any problems.
- Next message: Nick Hounsome: "Re: i/o Fortran's format commands in c++"
- Previous message: dullboy: "linker errors: LNK2005"
- In reply to: Jeff Schwab: "Re: [OT]Re: atomic flag"
- Next in thread: Jeff Schwab: "Re: [OT]Re: atomic flag"
- Reply: Jeff Schwab: "Re: [OT]Re: atomic flag"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|