Retrieving the detachstate attribute.
This example shows how to obtain the detachstate attribute of a thread
attribute object.
#include <pthread.h>
pthread_attr_t thread_attr; /* thread attribute object */
int detachstate; /* detachstate attribute */
int rc;
...
rc = pthread_attr_getdetachstate (&thread_attr, &detachstate);
if (rc!=0) {
/* handle error */
}
else {
/* legal values for detachstate are:
* PTHREAD_CREATE_DETACHED or PTHREAD_CREATE_JOINABLE
*/
}
[[ Note to the reviewers:
The pthread_attr_set* XSH refer to the pthread_attr_get*. So, maybe
we should incorporate also a "set" example? Or Do you think, it is
sufficient to just illustrate the pthread_attr_get*?
A point that causes me headaches is the following. Not all Pthreads
implementations check the validity of the attr parameter. If I
understood correctly, the standard doesn't require such a check.
As a result, pthread_attr_getdetachstate() might returns 0, but
detachstate has some garbage value, since the implementation
accesses the memory thinking that's a pthread_attr_t. That's what I
wanted to convey with the comments in the else clause.
After long considerations whether we should inform or not the reader
about this potential issue, I decide to silently ignore the problem
following Dave (Butenhof) statement:
" The standard is not designed to make UNIX, or signals, or threads,
or async I/O, or anything else "safe" for inexperienced programmers. "
However in view of ERN91, we could also make things "more convenients"
for this particular problem ;-) "strong" Pthreads implementations
already support this.
end of notes to the reviewers ]]
--
COMPUTERBILD 15/03: Premium-e-mail-Dienste im Test
--------------------------------------------------
1. GMX TopMail - Platz 1 und Testsieger!
2. GMX ProMail - Platz 2 und Preis-Qualitätssieger!
3. Arcor - 4. web.de - 5. T-Online - 6. freenet.de - 7. daybyday - 8. e-Post
|