source: CIVL/examples/pthread/bug3.cvl@ 37bfb99

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

Updated examples and pthread.cvh

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

  • Property mode set to 100644
File size: 1.4 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 at thread creation. Compare with hello_arg1.c.
11* Command line execution:
12* civl verify -inputNUM_THREADS=8 bug3.cvl
13******************************************************************************/
14#include "pthread.cvh"
15#include <civlc.h>
16#include <stdio.h>
17#include <stdlib.h>
18
19$input int NUM_THREADS;
20
21void *PrintHello(void *threadid){
22 long taskid = (long)*threadid;
23 //sleep(1);
24 printf("Hello from thread %d\n", taskid);
25 pthread_exit(NULL, false, NULL, 0);
26}
27
28int main(void){
29 pthread_t threads[NUM_THREADS];
30 int rc;
31 long t;
32
33 for(t=0;t<NUM_THREADS;t++) {
34 printf("Creating thread %d\n", t);
35 rc = pthread_create(&threads[t], NULL, PrintHello, (void *)&t);
36 if (rc) {
37 $assert(false, "ERROR; return code from pthread_create() is %d", rc);
38 return 0;
39 }
40 }
41 pthread_exit(NULL,true, threads, NUM_THREADS);
42 return 0;
43}
44
Note: See TracBrowser for help on using the repository browser.