Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming.threads > #1108
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Newsgroups | comp.lang.c, comp.programming.threads |
| Subject | Re: Trivial C11 threads.h wrapper (public domain) |
| Date | 2012-09-28 08:23 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <k444sg$3bk$1@dont-email.me> (permalink) |
| References | <slrnk67ihu.3ts.nuclear@goat.mutantstargoat.com> <50643C6A.6020609@web.de> <slrnk68us3.9lj.nuclear@goat.mutantstargoat.com> <50657671.1030606@web.de> |
Cross-posted to 2 groups.
On 09/28/2012 06:05 AM, Markus Elfring wrote: >> ... probably not, but it's not a matter of preference. >> Unless I'm much mistaken, the C11 standard dictates int as the type of >> the second argument of mtx_init (where all the mtx_ enumerations go), >> and as the return of all functions that need to indicate success >> or failure (thrd_ enumerations). > > I suggest generally that a name is assigned to an enumeration. It might also be > a nice service if a "typedef" will be provided for each enumeration so that it > can become easier to reuse them as a data type in customised data structures. He's trying to do the best that he can to implement a C99 substitute for a new feature of C2011. C2011 does NOT specify a typedef name (or even an enum tag) for the enumeration constants required to be declared in <threads.h>. An implementation could provide a tag or a typedef or both, but it can only use a reserved identifier for those purposes. If he used a reserved identifier for that purpose, it would make his C99 code have undefined behavior. If he used an identifier that was not reserved, his substitute would be inappropriately infringing on the user's name space. >> Yes that was the most hairy bit. This mechanism doesn't seem to map >> exactly to what C11 wants. For instance the C standard talks about the >> possibility of having a mtx_timed | mtx_recursive mutex, but as far as >> I can tell with pthreads I can specify either PTHREAD_MUTEX_RECURSIVE or >> PTHREAD_MUTEX_TIMED_NP (which is not even standard), but not both. > > Thanks that you pointed out such a portability issue. > > I would like to point out once again that your function call > "pthread_mutexattr_init" shows the case of an unused return value. I would > prefer complete error detection and corresponding exception handling. I agree - mtx_init() should return thrd_error if pthread_mutexattr_init() returns a non-zero value. > Some functions from the C standard API (like "mtx_destroy") have got the return > type "void". But the called Pthreads function provides an error code eventually. > How do you think about the reaction "abort()" in this use case? mtx_destroy() has, in itself, well-defined behavior that does not include calling abort(). However, pthread_mutex_destroy() is only allowed to fail if "The implementation has detected an attempt to destroy the object referenced by mutex while it is locked or referenced (for example, while being used in a pthread_cond_timedwait() or pthread_cond_wait()) by another thread." I haven't studied the C2011 threading specification carefully enough to be certain, but I suspect that if C code using this wrapper library could set up a situation in which pthread_mutex_destroy() would fail, that code which does so might itself have undefined behavior, according to C2011. If so, that would be sufficient to justify having mtx_destroy() call abort(). -- James Kuyper
Back to comp.programming.threads | Previous | Next — Previous in thread | Next in thread | Find similar
Trivial C11 threads.h wrapper (public domain) John Tsiombikas <nuclear@member.fsf.org> - 2012-09-27 03:38 +0000
Re: Trivial C11 threads.h wrapper (public domain) Keith Thompson <kst-u@mib.org> - 2012-09-26 20:50 -0700
Re: Trivial C11 threads.h wrapper (public domain) John Tsiombikas <nuclear@member.fsf.org> - 2012-09-27 04:15 +0000
Re: Trivial C11 threads.h wrapper (public domain) Lorenzo Beretta <lory.fulgi@infinito.it> - 2012-09-27 16:35 +0200
Re: Trivial C11 threads.h wrapper (public domain) John Tsiombikas <nuclear@member.fsf.org> - 2012-09-27 15:58 +0000
Re: Trivial C11 threads.h wrapper (public domain) Lorenzo Beretta <lory.fulgi@infinito.it> - 2012-09-27 18:27 +0200
Re: Trivial C11 threads.h wrapper (public domain) William Ahern <william@wilbur.25thandClement.com> - 2012-09-28 12:08 -0700
Re: Trivial C11 threads.h wrapper (public domain) Kaz Kylheku <kaz@kylheku.com> - 2012-09-28 19:38 +0000
Re: Trivial C11 threads.h wrapper (public domain) Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-09-28 15:50 -0400
Re: Trivial C11 threads.h wrapper (public domain) Lorenzo Beretta <lory.fulgi@infinito.it> - 2012-09-29 18:41 +0200
Re: Trivial C11 threads.h wrapper (public domain) Markus Elfring <Markus.Elfring@web.de> - 2012-09-27 13:45 +0200
Re: Trivial C11 threads.h wrapper (public domain) John Tsiombikas <nuclear@member.fsf.org> - 2012-09-27 16:14 +0000
Re: Trivial C11 threads.h wrapper (public domain) Markus Elfring <Markus.Elfring@web.de> - 2012-09-28 12:05 +0200
Re: Trivial C11 threads.h wrapper (public domain) Keith Thompson <kst-u@mib.org> - 2012-09-28 03:39 -0700
Re: Trivial C11 threads.h wrapper (public domain) James Kuyper <jameskuyper@verizon.net> - 2012-09-28 08:23 -0400
Re: Trivial C11 threads.h wrapper (public domain) John Tsiombikas <nuclear@member.fsf.org> - 2012-09-28 19:48 +0000
Re: Trivial C11 threads.h wrapper (public domain) Toby Douglass <a@b.com> - 2012-10-01 20:19 +0200
Re: Trivial C11 threads.h wrapper (public domain) James Kuyper <jameskuyper@verizon.net> - 2012-10-01 14:37 -0400
Re: Trivial C11 threads.h wrapper (public domain) Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-10-01 14:38 -0400
Re: Trivial C11 threads.h wrapper (public domain) Keith Thompson <kst-u@mib.org> - 2012-10-01 14:58 -0700
Re: Trivial C11 threads.h wrapper (public domain) Jens Gustedt <jens.gustedt@loria.fr> - 2012-09-28 20:22 +0200
Re: Trivial C11 threads.h wrapper (public domain) Markus Elfring <Markus.Elfring@web.de> - 2012-09-30 23:13 +0200
Re: Trivial C11 threads.h wrapper (public domain) Keith Thompson <kst-u@mib.org> - 2012-09-30 14:28 -0700
Re: Trivial C11 threads.h wrapper (public domain) Jens Gustedt <jens.gustedt@loria.fr> - 2012-10-01 00:37 +0200
Re: Trivial C11 threads.h wrapper (public domain) Jens Gustedt <jens.gustedt@loria.fr> - 2012-10-01 00:44 +0200
Re: Trivial C11 threads.h wrapper (public domain) Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-09-30 19:48 -0400
Re: Trivial C11 threads.h wrapper (public domain) Jens Gustedt <jens.gustedt@loria.fr> - 2012-10-01 08:26 +0200
Re: Trivial C11 threads.h wrapper (public domain) Markus Elfring <Markus.Elfring@web.de> - 2012-10-01 11:25 +0200
Re: Trivial C11 threads.h wrapper (public domain) Jens Gustedt <jens.gustedt@loria.fr> - 2012-10-01 11:47 +0200
Re: Trivial C11 threads.h wrapper (public domain) Markus Elfring <Markus.Elfring@web.de> - 2012-10-01 12:05 +0200
Re: Trivial C11 threads.h wrapper (public domain) Jens Gustedt <jens.gustedt@loria.fr> - 2012-10-01 13:15 +0200
Clarification for interface specification "C11 threads.h" Markus Elfring <Markus.Elfring@web.de> - 2012-10-03 11:02 +0200
Re: Clarification for interface specification "C11 threads.h" Keith Thompson <kst-u@mib.org> - 2012-10-03 13:29 -0700
Re: Clarification for interface specification "C11 threads.h" Jens Gustedt <jens.gustedt@loria.fr> - 2012-10-04 13:35 +0200
Re: Clarification for interface specification "C11 threads.h" Markus Elfring <Markus.Elfring@web.de> - 2012-10-12 17:45 +0200
Re: Trivial C11 threads.h wrapper (public domain) Noob <root@127.0.0.1> - 2012-10-01 18:10 +0200
Re: Trivial C11 threads.h wrapper (public domain) Nick Bowler <nbowler@draconx.ca> - 2012-10-01 19:28 +0000
Re: Trivial C11 threads.h wrapper (public domain) Keith Thompson <kst-u@mib.org> - 2012-10-01 15:19 -0700
Re: Trivial C11 threads.h wrapper (public domain) Kaz Kylheku <kaz@kylheku.com> - 2012-10-01 23:57 +0000
Re: Trivial C11 threads.h wrapper (public domain) Jens Gustedt <jens.gustedt@loria.fr> - 2012-10-02 14:48 +0200
csiph-web