Le 18/04/12 13:56, Wojtek Lerch a écrit :
> On 17/04/2012 4:18 PM, Joshua Maurice wrote:
>>
http://pubs.opengroup.org/onlinepubs/009604499/functions/pthread_key_create.html
>>
>>> int pthread_key_create(pthread_key_t *key, void (*destructor)(void*));
>> [partial quote]
>> An optional destructor function may be associated with each key value.
>> At thread exit, if a key value has a non-NULL destructor pointer, and
>> the thread has a non-NULL value associated with that key, the value of
>> the key is set to NULL, and then the function pointed to is called
>> with the previously associated value as its sole argument. The order
>> of destructor calls is unspecified if more than one destructor exists
>> for a thread when it exits.
>> [/quote]
>
> The C standard doesn't contain anything resembling the above, does it?
>
Yes, and that is the problem... They SHOULD have copied the pthread
standard instead of relying in Dinkum's library.
Now we are faced with the huge task of debugging a complete new
threading standard, what will take us at least several years of efforts.
The C standards committee has neither the material means (budget) nor
the intellectual competences for doing such an enormous task.
>> Oh wait, the C standard just more or less copied the POSIX semantics
>> in this case, including the POSIX wording, including the word
>> "destructor".
>
> Which POSIX wording? I have counted three places that use the word
> "destructor" in the C standard, and only one one of them actually talks
> about the behaviour of destructors -- unfortunately, without going into
> details.
I reported that in a detailed bug report on 2010. Then I repeated it in
much more stronger terms in 2011 (July) complaining that my 2010 bug
reports went unnoticed. Now the bugs are published as a standard.
How can be they so isolated from the community?
What is the point of the publication processes initiating a "discussion"
phase if the bug reports go to /dev/null ???
All it says is that TSS_DTOR_ITERATIONS specifies the maximum
> number of times that destructors will be called when a thread
> terminates. I have not found any mention of whether destructors might be
> called an any other time, what arguments they're called with, or even
> whether the TSS_DTOR_ITERATIONS limit specifies the total number of
> destructor calls per program, per thread, per destructor, or perhaps
> something else.
I understood that was the total number of destructors called but Mr
Gustedt (see his message in this same thread) thinks that is the total
number of calls to a *single* destructor is called when a thread
terminates. Anyway there is no way to know until the committee decides
to fill the gaps. This is ridiculous.
>
> (In case it makes a difference, I was using N1570 instead of the
> official standard, but my understanding is that it doesn't, does it?)
>
>> Your second complaint: It might be that the C standard is
>> underspecified, or that the specification is silly and broken. If it
>> is underspecified, then I agree that's unfortunate, and I would look
>> to the pthread spec for clarification in the interim, as that's what
>> everyone else will probably do. If you think the spec is silly and
>> broken, then I ask "what is a better spec?", and I ask what do you
>> think about pthread compatibility?
>
> What specification? The problem, when it comes to destructors, is that
> the specification is pretty much non-existent. The only way to guess the
> intent is by noticing the resemblance to POSIX, and ignoring the fact
> that C decided to drop the word "key" and refer to the keys as
> "thread-specific storage pointers", as if they where thread-specific. (I
> guess that can easily count as silly and broken.)
Well, since I work mainly in windows I am not that familiar with
pthreads, not because I have anything against pthreads but just because
I did not study it. Then, I did not see any similarities between
pthreads specs and C standard specs.
What I am 100% sure is that the whole specification of the C standard
is a cut and paste copy of the specifications of the thread library of
the company of Mr Plauger, one of the committee members.
I would have nothing against that either if those specs were correct
but they aren't. They are just a specific library documentation mainly
for C++ users. To directly use that in the C standard is quite strange
really.
Other bugs that I signaled but made their way into the standard are:
The types are:
(1)
cnd_t
which is a complete object type that holds an identifier for a condition
variable;
thrd_t
which is a complete object type that holds an identifier for a thread;
The whole standard text uses the word "identifier" with a WELL DEFINED
MEANING. In the threads chapter however, this word is used with a
different meaning without any explanation of what they are talking
about: what "identifier" ???
Probably this is a numeric value that is used to identify a condition or
a thread, but nowhere is that specified.
(2)
The time functions that use an "xtime". When I want to have a timeout of
(say) 5 seconds, should I:
A: do an xtime_get to get the current time
B: Add 5 seconds to the current time
C: Pass that to the timeout functions
OR
A: pass (xtime){5,0} to the timeout functions?
I.e. do the timeout functions use an xtime that should contain just the
timeout or the current time + the timeout?
This is NOT SPECIFIED!!!
The ONLY specs about the epoch that the timeout uses is that xtime_get
uses a "base" argument that MUST be "TIME_UTC".
The "TIME_UTC" symbol is NOWHERE described and nobody can know what it
should contain; what its type is or what it should be. IT APPEARS
NOWHERE ELSE. The only sentence where this appears is in the docs of the
xtime_get function.
Synopsis
#include <threads.h>
int xtime_get(xtime *xt, int base);
Description
The xtime_get function sets the xtime object pointed to by xt to hold
the current time based on the time base base.
Returns
If the xtime_get function is successful it returns the nonzero value
base, which must be TIME_UTC; otherwise, it returns zero.
Why does xtime_get have a 2nd argument that MUST be always the same
value (TIME_UTC whatever that is)? If they wanted to leave place for
future expansions they should have said so.
What is that TIME_UTC?
Yes, since UTC *could* mean Universal Time Coordinates it *COULD* be
that the timeout should be in UTC coordinates. This would mean that
timeouts longer than 24 hours are forbidden since UTC coordinates just
describe the offset to add/subtract for getting the local time...