source: CIVL/examples/pthread/bug3.c@ 325d439

1.23 2.0 main test-branch
Last change on this file since 325d439 was cf74da3, checked in by John Edenhofner <johneden@…>, 12 years ago

Updated pthread.cvh and examples

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@1033 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 978 bytes
Line 
1/*****************************************************************************
2* FILE: bug3.c
3* DESCRIPTION:
4* This "hello world" Pthreads program demonstrates an unsafe (incorrect)
5* way to pass thread arguments at thread creation. Compare with hello_arg1.c.
6* AUTHOR: Blaise Barney
7* LAST REVISED: 01/29/09
8******************************************************************************/
9#include <pthread.h>
10#include <stdio.h>
11#include <stdlib.h>
12#define NUM_THREADS 8
13
14void *PrintHello(void *threadid)
15{
16 long taskid = (long)threadid;
17 sleep(1);
18 printf("Hello from thread %ld\n", taskid);
19 pthread_exit(NULL);
20}
21
22int main(int argc, char *argv[])
23{
24pthread_t threads[NUM_THREADS];
25int rc;
26long t;
27
28for(t=0;t<NUM_THREADS;t++) {
29 printf("Creating thread %ld\n", t);
30 rc = pthread_create(&threads[t], NULL, PrintHello, (void *) &t);
31 if (rc) {
32 printf("ERROR; return code from pthread_create() is %d\n", rc);
33 exit(-1);
34 }
35 }
36
37pthread_exit(NULL);
38}
39
Note: See TracBrowser for help on using the repository browser.