source: CIVL/examples/pthread/bug5.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.6 KB
RevLine 
[8090425]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
[38374b7]6* DESCRIPTION:
7* A simple pthreads program that dies before the threads can do their
[6fe2cd9]8* work because pthread_exit() is not called.
[8090425]9* Command line execution:
10* civl verify -inputNUM_THREADS=5 bug5.cvl
[38374b7]11******************************************************************************/
[6fe2cd9]12
[38374b7]13#include "pthread.cvh"
14#include <civlc.h>
15#include <stdio.h>
16#include <stdlib.h>
[cf74da3]17#include "math.cvh"
[8090425]18
19$input int NUM_THREADS;
[38374b7]20
21void *PrintHello(void *threadid)
22{
[6fe2cd9]23 int i;
24 double myresult=0.0;
25 printf("thread=%d: starting...\n", threadid); // Removed l from %ld
26 for (i=0; i<1000; i++)
27 myresult += sin(i) * tan(i);
28 printf("thread=%d result=%e. Done.\n",threadid,myresult); // Removed l from %ld
29 pthread_exit(NULL, false, NULL, 0); //Different parameters
[38374b7]30}
31
[ca52517]32int main(void)
[38374b7]33{
[6fe2cd9]34 pthread_t threads[NUM_THREADS];
35 int rc, i;
36 long t[NUM_THREADS];
37
38 for(i=0;i<NUM_THREADS;i++){
39 printf("Main: creating thread %d\n", t);
40 //Add values into array and use address so that each value is unique as int to void * conversion is not supported
41 t[i] = (long)i;
42 rc = pthread_create(&threads[i], NULL, PrintHello, (void *)&t[i]);
43 if (rc){
44 printf("ERROR; return code from pthread_create() is %d\n", rc);
45 exit(-1);
[38374b7]46 }
47 }
[6fe2cd9]48 //pthread_exit(NULL, true, threads, NUM_THREADS); // This is the bug, no pthread_exit causes error
49 printf("Main: Done.\n");
[38374b7]50}
51
Note: See TracBrowser for help on using the repository browser.