source: CIVL/examples/pthread/bug5.cvl@ 761eb6f

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

Updated headers for examples

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

  • Property mode set to 100644
File size: 1.3 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* FILE: bug5.cvl
6* DESCRIPTION:
7* A simple pthreads program that dies before the threads can do their
8* work. Figure out why.
9* Command line execution:
10* civl verify -inputNUM_THREADS=5 bug5.cvl
11******************************************************************************/
12#include "pthread.cvh"
13#include <civlc.h>
14#include <stdio.h>
15#include <stdlib.h>
16#include <math.h>
17
18$input int NUM_THREADS;
19
20void *PrintHello(void *threadid)
21{
22 int i;
23 double myresult=0.0;
24 printf("thread=%d: starting...\n", threadid); // Removed l from %ld
25 for (i=0; i<1000000; i++)
26 myresult += sin(i) * tan(i);
27 printf("thread=%d result=%e. Done.\n",threadid,myresult); // Removed l from %ld
28 pthread_exit(NULL);
29}
30
31int main(int argc, char *argv[])
32{
33pthread_t threads[NUM_THREADS];
34int rc;
35long t;
36for(t=0;t<NUM_THREADS;t++){
37 printf("Main: creating thread %ld\n", t);
38 rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);
39 if (rc){
40 printf("ERROR; return code from pthread_create() is %d\n", rc);
41 exit(-1);
42 }
43 }
44printf("Main: Done.\n");
45}
46
Note: See TracBrowser for help on using the repository browser.