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

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

Almost done

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

  • Property mode set to 100644
File size: 1.5 KB
Line 
1/*****************************************************************************
2* SOURCE: This is a translation of a Pthread program from the Lawrence Livermore
3* Computing Center POSIX Threads Programming Exercise at:
4* https://computing.llnl.gov/tutorials/pthreads/exercise.html
5* SUPERSOURCE: Adapted from example code in "Pthreads Programming", B. Nichols
6* et al. O'Reilly and Associates.
7* FILE: bug3.cvl
8* DESCRIPTION:
9* This "hello world" Pthreads program demonstrates an unsafe (incorrect)
10* way to pass thread arguments by address at thread creation resulting in
11* a non-unique value for each thread's argument.
12* Command line execution:
13* civl verify -inputNUM_THREADS=8 bug3.cvl
14******************************************************************************/
15
16#include "pthread.cvh"
17#include <civlc.h>
18#include <stdio.h>
19#include <stdlib.h>
20
21$input int NUM_THREADS;
22
23void *PrintHello(void *threadid){
24 long taskid = (long)*threadid; // Dereference rather than direct conv
25
26 //sleep(1);
27 printf("Hello from thread %d\n", taskid);
28 pthread_exit(NULL, false, NULL, 0); //Different parameters
29}
30
31int main(void){
32 pthread_t threads[NUM_THREADS];
33 int rc;
34 long t;
35
36 for(t=0;t<NUM_THREADS;t++) {
37 printf("Creating thread %d\n", t);
38 rc = pthread_create(&threads[t], NULL, PrintHello, (void *)&t);
39 if (rc) {
40 $assert(false, "ERROR; return code from pthread_create() is %d", rc);
41 return 0;
42 }
43 }
44 pthread_exit(NULL,true, threads, NUM_THREADS); //Different parameters
45 return 0;
46}
47
Note: See TracBrowser for help on using the repository browser.