This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: pthread_mutex_t initializer idiom
- From: Loren James Rittle <rittle at latour dot labs dot mot dot com>
- To: libstdc++ at gcc dot gnu dot org
- Date: Fri, 8 Sep 2006 13:18:47 -0500 (CDT)
- Subject: Re: pthread_mutex_t initializer idiom
- Reply-to: rittle at labs dot mot dot com
Benjamin wrote:
> I'm still trying to unify some of the atomics and concurrency code, and
> remove duplicates.
Ah, I see that the clean up of the mess that I helped create (while
IMHO fixing a much bigger mess ;-) many blue moons ago continues...
> I see this idiom a lot:
> __gthread_mutex_t temp = __GTHREAD_MUTEX_INIT;
> _M_mutex = temp;
> Can somebody explain to me why we are doing this instead of:
> _M_mutex = __GTHREAD_MUTEX_INIT;
> ?
It may be possible to write the one-line portable version with a
different idiom but we never found it back when we converted the
library to use the gthread abstraction layer. [Yes, I knew of this:
_M_mutex = (__gthread_mutex_t) __GTHREAD_MUTEX_INIT;
but there may be some system or other reason why it doesn't work here.]
> Is this something to do with the gthread abstraction layer and POD mutexes?
Yes, indeed. To repeat: We must assume the absolute worst case in
terms of how the __GTHREAD_MUTEX_INIT macro may expand.
Regards,
Loren
PS, unless someone can prove otherwise via cvs/svn logs, I hereby take
full credit for the "Do not copy a POSIX/gthr mutex once in use.
However, bits are bits." comment. ;-)