source: CIVL/examples/pthread/lnll/bug3.c@ e0fc189

1.23 2.0 main test-branch
Last change on this file since e0fc189 was e3151da, checked in by Ziqing Luo <ziqing@…>, 11 years ago

re-organized example directory

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@1763 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.h>
10#include <stdio.h>
11#include <stdlib.h>
12#define NUM_THREADS 2
13
14void *PrintHello(void *threadid)
15{
16 long taskid = *((long*)threadid);
17 //sleep(1);
18 printf("Hello from thread %ld\n", taskid);
19 #pragma CIVL $assert(taskid != NUM_THREADS);
20 pthread_exit(NULL);
21}
22
23int main(int argc, char *argv[])
24{
25pthread_t threads[NUM_THREADS];
26int rc;
27long t;
28
29for(t=0;t<NUM_THREADS;t++) {
30 printf("Creating thread %ld\n", t);
31 rc = pthread_create(&threads[t], NULL, PrintHello, (void *) &t);
32 if (rc) {
33 printf("ERROR; return code from pthread_create() is %d\n", rc);
34 exit(-1);
35 }
36 }
37
38pthread_exit(NULL);
39}
40
Note: See TracBrowser for help on using the repository browser.