| 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 |
#include <stdio.h> |
| 9 |
|
| 10 |
/* Prints x's to stderr. The parameter is unused. Does not return. */ |
| 11 |
|
| 12 |
void* print_xs (void* unused) |
| 13 |
{ |
| 14 |
while (1) |
| 15 |
fputc ('x', stderr); |
| 16 |
return NULL; |
| 17 |
} |
| 18 |
|
| 19 |
/* The main program. */ |
| 20 |
|
| 21 |
int main () |
| 22 |
{ |
| 23 |
pthread_t thread_id; |
| 24 |
/* Create a new thread. The new thread will run the print_xs |
| 25 |
function. */ |
| 26 |
pthread_create (&thread_id, NULL, &print_xs, NULL); |
| 27 |
/* Print o's continuously to stderr. */ |
| 28 |
while (1) |
| 29 |
fputc ('o', stderr); |
| 30 |
return 0; |
| 31 |
} |