This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: pthread_mutex_t initializer idiom


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. ;-)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]