[cpp-threads] Re: Thread API interface tweaks
Alexander Terekhov
alexander.terekhov at gmail.com
Fri Sep 1 17:43:40 BST 2006
On 9/1/06, Ion Gaztañaga <igaztanaga at gmail.com> wrote:
> > [...]
> > > >> void unlock()
> > > >> {
> > > >> if (--count_ == 0)
> > > >> {
> > > >> id_ = thread_id(); // id_ = "not a thread"
> > > >
> > > > ... and here... data race?
> > >
> > > It is undefined for a thread for which id_ != self to call unlock().
> >
> > True, but think about thread id re-use. You need to delay re-use until
> > id_ = thread_id() becomes globally visible and there's nothing in your
> > code that ensures it, AFAICS.
>
> Sorry if I'm wrong, but does not thread creation/destruction involve
> memory synchronization? Hasn't pthread_create() release sematics and
http://www.opengroup.org/austin/mailarchives/ag-review/msg02017.html
> pthread_join() acquire semantics? So if a thread ends all previous
> operations shouldn't be completed (including writing an invalid
> thread_id)?
You seem to make assumptions. Suppose that a thread doing unlock() is
a POSIX detached thread so you just can't join it.
>
> And if this does not guarantee anything, isn't any way to make
> Howard's code correct adding some memory synchronization instruction?
I don't see how.
regards,
alexander.
More information about the cpp-threads
mailing list