Path: csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: Kaz Kylheku Newsgroups: comp.lang.c,comp.programming.threads Subject: Re: Trivial C11 threads.h wrapper (public domain) Followup-To: comp.lang.c Date: Mon, 1 Oct 2012 23:57:37 +0000 (UTC) Organization: Aioe.org NNTP Server Lines: 17 Message-ID: <20121001160916.879@kylheku.com> References: <5065EAFD.1050102@loria.fr> <5068B604.9020606@web.de> <5068C9C3.6090502@loria.fr> <50696193.3090503@web.de> <506966CA.6080308@loria.fr> NNTP-Posting-Host: X+c6YNb3AaWMPA3YfA4opg.user.speranza.aioe.org X-Complaints-To: abuse@aioe.org User-Agent: slrn/pre1.0.0-18 (Linux) X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.c:26947 comp.programming.threads:1159 On 2012-10-01, Keith Thompson wrote: > So what does mtx_destroy() do if some thread *is* blocked waiting > for mtx? What if some thread is using a pointer P and another one calls free(P)? The program is broken in that situation. One thread is finalizing an object, but it has no right to do that because the object is referenced elsewhere. The real POSIX API provides return values for situations like this: EBUSY (the mutex is being destroyed while it is locked or in use) and EINVAL: the mutex is invalid. However, these return values are optional! Implementations do not have check these situations. (Not even for mutexes attributed as having type PTHREAD_MUTEX_ERRORCHECK: that type causes certain very specific debugging checks to be required in the lock and unlock operations only.)