Email List: Xaustin-group-lX
[All Lists]

Re: safe use of pthread_xxx_init functions

To: austin-group-l@xxxxxxxxxxxxx
Subject: Re: safe use of pthread_xxx_init functions
From: Larry Dwyer <Larry.Dwyer@xxxxxx>
Date: Thu, 15 Feb 2007 12:09:50 -0800
References: <45D3669E.2010903@xxxxxx><1171484522.27476.67.camel@amstaff2.msbit.com><45D385B0.9080406@xxxxxx><1171492211.27476.94.camel@amstaff2.msbit.com><45D39706.4090405@xxxxxx><1171496494.27476.99.camel@amstaff2.msbit.com><45D3AD15.50803@xxxxxx><200702150759.XAA02158@xxxxxx><1171563516.10413.20.camel@amstaff2.msbit.com><DF5ABF5D-8EE5-4294-BE53-BE0ED6C3479B@xxxxxx><200702151941.LAA29572@xxxxxx><45D4B91B.7060306@xxxxxx>
At 11:48 AM 2/15/2007, Wojtek Lerch wrote:
Larry Dwyer wrote:
It would be wrong for the implementation to reject the request to initialize the object because of a misguided desire on the part of the system implementors to protect the lazy/stupid/careless application developers from themselves.
No it wouldn't:

"The pthread_mutex_init() function may fail if:

[EBUSY]
The implementation has detected an attempt to reinitialize the object referenced by mutex, a previously initialized, but not yet destroyed, mutex."
The operant condition is "may fail".

Mutex's are special cases anyway. Since mutex objects are shared by multiple threads, and the locking of a mutex is done by many threads, there are special conditions imposed on the implementation that may be difficult to meet unless the implementation is allowed to do something that consumes resources and/or maintains state beyond what the application does, such as allocating memory. If the destroy was not called, the implementation-allocated-memory would become a memory leak.

It is OK for the application to abandon any memory it allocates. It is not OK for the implementation to abandon hidden memory that it allocates on behalf of the application.

Cheers,
Larry

Cheers,
Larry

<Prev in Thread] Current Thread [Next in Thread>