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 | * 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 bug3.cvl
|
|---|
| 13 | ******************************************************************************/
|
|---|
| 14 | #include "pthread.cvh"
|
|---|
| 15 | #include <civlc.h>
|
|---|
| 16 | #include <stdio.h>
|
|---|
| 17 | #include <stdlib.h>
|
|---|
| 18 | #define NUM_THREADS 8
|
|---|
| 19 |
|
|---|
| 20 | void *PrintHello(void *threadid){
|
|---|
| 21 | long taskid = (long)*threadid;
|
|---|
| 22 | //sleep(1);
|
|---|
| 23 | printf("Hello from thread %d\n", taskid);
|
|---|
| 24 | //pthread_exit(NULL);
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | int main(int argc, char *argv[]){
|
|---|
| 28 | pthread_t threads[NUM_THREADS];
|
|---|
| 29 | int rc;
|
|---|
| 30 | long t;
|
|---|
| 31 |
|
|---|
| 32 | for(t=0;t<NUM_THREADS;t++) {
|
|---|
| 33 | printf("Creating thread %d\n", t);
|
|---|
| 34 | rc = pthread_create(&threads[t], NULL, PrintHello, (void *)&t);
|
|---|
| 35 | if (rc) {
|
|---|
| 36 | printf("ERROR; return code from pthread_create() is %d\n", rc);
|
|---|
| 37 | exit(-1);
|
|---|
| 38 | $assert($false, "ERROR; return code from pthread_create() is");
|
|---|
| 39 | }
|
|---|
| 40 | }
|
|---|
| 41 | //pthread_exit(NULL);
|
|---|
| 42 | return 0;
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.