diff --git a/threads.c b/threads.c new file mode 100644 --- /dev/null +++ b/threads.c @@ -0,0 +1,49 @@ +/** + * $Id: threads.c,v 1.1.1.1 2008-04-28 17:32:53 mbroeker Exp $ + * $Source: /development/c/demos/threads.c,v $ + */ + +#include +#include + +#include +#include + +void *thread_func (void *vptr_args); + +void do_some_work (void) +{ + time_t start_time = time (NULL); + + while (time (NULL) == start_time); /* busy-wait for 0-1 seconds */ +} + +int main (int argc, char **argv) +{ + int i; + pthread_t thread; + + pthread_create (&thread, NULL, &thread_func, NULL); + + for (i = 0; i < 20; ++i) { + fprintf (stdout, "a\n"); + + do_some_work (); + } + + pthread_join (thread, NULL); + + exit (EXIT_SUCCESS); +} + +void *thread_func (void *vptr_args) +{ + int i; + + for (i = 0; i < 20; ++i) { + fprintf (stderr, " b\n"); + + do_some_work (); + } + return NULL; +}