When beginning to see the first few "alarm" code errors.h Where children did not find the original. . .
#include <pthread.h> #include <stdio.h> #include <errno.h> #include < String .h> int main ( int argc, char * the argv []) { pthread_t Thread; int Status; / * from deadlock example: * in most cases, uninitialized variable pthread_t is an invalid thread ID, the calling thread recovery function normally check out the cause of the error; but there may be an uninitialized value is a valid ID, at this time, this thread entered from the deadlock. * / Status = pthread_join (Thread, NULL); iF (! Status = 0 ) { / * the strerror: When information of interest * is different from perror errno current corresponding to the standard error, * Strerror errno is designated a, and returns an error string, the device is not redirected to the standard. * / Fprintf (stderr, " error% D:% S \ n- " , Status, the strerror (Status)); return Status; } return 0 ; }
#ifndef __errors_h #define __errors_h #include <unistd.h> #include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #ifdef DEBUG #define DPRINTF(arg) printf arg #else #define DPRINTF(arg) #endif #define err_abort(code, text) do { \ fprintf(stderr, "%s at \"%s\":%d: %s\n", \ text, __FILE__, __LINE__, strerror(code)); \ abort(); \ } while(0) #define errno_abort(text) do { \ fprintf(stderr, "%s at \"%s\":%d: %s\n", \ text, __FILE__, __LINE__, strerror(code)); \ abort(); \ } while(0) #endif