| 1 |
/*********************************************************************** |
| 2 |
* Code listing from "Advanced Linux Programming," by CodeSourcery LLC * |
| 3 |
* Copyright (C) 2001 by New Riders Publishing * |
| 4 |
* See COPYRIGHT for license information. * |
| 5 |
***********************************************************************/ |
| 6 |
|
| 7 |
#include <pthread.h> |
| 8 |
|
| 9 |
void* thread_function (void* thread_arg) |
| 10 |
{ |
| 11 |
/* Do work here... */ |
| 12 |
return NULL; |
| 13 |
} |
| 14 |
|
| 15 |
int main () |
| 16 |
{ |
| 17 |
pthread_attr_t attr; |
| 18 |
pthread_t thread; |
| 19 |
|
| 20 |
pthread_attr_init (&attr); |
| 21 |
pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); |
| 22 |
pthread_create (&thread, &attr, &thread_function, NULL); |
| 23 |
pthread_attr_destroy (&attr); |
| 24 |
|
| 25 |
/* Do work here... */ |
| 26 |
|
| 27 |
/* No need to join the second thread. */ |
| 28 |
return 0; |
| 29 |
} |