1.23
2.0
main
test-branch
| 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 |
|
|---|
| 20 | void *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 |
|
|---|
| 31 | int main(int argc, char *argv[])
|
|---|
| 32 | {
|
|---|
| 33 | pthread_t threads[NUM_THREADS];
|
|---|
| 34 | int rc;
|
|---|
| 35 | long t;
|
|---|
| 36 | for(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 | }
|
|---|
| 44 | printf("Main: Done.\n");
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.