TOC PREV NEXT INDEX

POSIX 1.c Migration Guide


Error Reporting

Pthread Function Errors

As noted in "Overview of Major Changes", virtually all pthreads functions defined by POSIX.1c return the error number as the return value of the function instead of setting errno as in POSIX.4a, except where required by existing practice. This requires that error detection and handling for these functions be modified in a manner similar to the following code fragments:

POSIX.4a Code

:
if (pthread_create(&tid, &attr, thread1, NULL) == -1) {
perror("pthread_create");
exit(-1);
}
:

Equivalent POSIX.1c Code

:
int rv; // For function return value
:
rv = pthread_create(&tid, &attr, thread1, NULL);
if (rv != 0) {
fprintf(stderr,
"ERROR: pthread_create returned %d\n", rv);
exit(-1);
}
:

Because such POSIX.1c functions do not set errno, the application cannot use the C Standard function perror() to print the corresponding system error message. An alternative, but non-portable, method of printing the system error message corresponding to the function return value on LynxOS 4 is to use the ERRMSG macro defined in errno.h to access the error message table:

rv = pthread_create(&tid, &attr, thread1, NULL);
if (rv != 0) {
fprintf(stderr,"pthread_create:%s\n", ERRMSG(rv));
}

Note: Assigning the function return value to errno is strongly discouraged, especially to return status from non-root threads using
pthread_exit((void *)&errno)
.
Although errno is implemented as a per-thread variable in LynxOS, the storage for this per-thread data is persistent only during a thread's lifetime. After the thread terminates, this storage may be reused for other purposes at any time, rendering any error information invalid.

Elimination of EINTR Return Code

POSIX.4a allowed blocking pthreads functions to return an EINTR error if interrupted by a signal handler in a manner consistent with many blocking POSIX.1 or POSIX.1b interfaces. LynxOS versions prior to 3.1.0 exhibited this behavior, requiring the application to handle these situations.

POSIX.1c disallows this behavior, requiring all blocking pthreads functions to restart or complete after the execution of a signal handler transparently to the application. POSIX.1 or POSIX.1b blocking function behavior is unchanged.



LynuxWorks, Inc.
855 Branham Lane East
San Jose, CA 95138
http://www.lynuxworks.com
1.800.255.5969
TOC PREV NEXT INDEX