source: CIVL/examples/pthread/bug3.cvl@ fe8b067

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

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

  • Property mode set to 100644
File size: 1.0 KB
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.cvh"
10#include <civlc.h>
11#include <stdio.h>
12#include <stdlib.h>
13#define NUM_THREADS 8
14
15void *PrintHello(void *threadid){
16 long taskid = (long)*threadid;
17 //sleep(1);
18 printf("Hello from thread %d\n", taskid);
19 pthread_exit(NULL);
20}
21
22int main(int argc, char *argv[]){
23 pthread_t threads[NUM_THREADS];
24 int rc;
25 long t;
26
27 for(t=0;t<NUM_THREADS;t++) {
28 printf("Creating thread %d\n", t);
29 rc = pthread_create(&threads[t], NULL, PrintHello, (void *)&t);
30 if (rc) {
31 printf("ERROR; return code from pthread_create() is %d\n", rc);
32 exit(-1);
33 }
34 }
35 //pthread_exit(NULL);
36 return 0;
37}
38
Note: See TracBrowser for help on using the repository browser.