[cpp-threads] Re: Thread API interface tweaks

Ion Gaztañaga igaztanaga at gmail.com
Fri Sep 1 17:07:35 BST 2006


> [...]
> > >>     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
pthread_join() acquire semantics? So if a thread ends all previous
operations shouldn't be completed (including writing an invalid
thread_id)?

And if this does not guarantee anything, isn't any way to make
Howard's code correct adding some memory synchronization instruction?

Regards,

Ion



More information about the cpp-threads mailing list