source: CIVL/examples/pthread/bug3.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.5 KB
RevLine 
[38374b7]1/*****************************************************************************
[9f23e8b]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
[38374b7]8* DESCRIPTION:
9* This "hello world" Pthreads program demonstrates an unsafe (incorrect)
[6fe2cd9]10* way to pass thread arguments by address at thread creation resulting in
11* a non-unique value for each thread's argument.
[9f23e8b]12* Command line execution:
[8090425]13* civl verify -inputNUM_THREADS=8 bug3.cvl
[38374b7]14******************************************************************************/
[6fe2cd9]15
[38374b7]16#include "pthread.cvh"
17#include <civlc.h>
18#include <stdio.h>
19#include <stdlib.h>
[8090425]20
21$input int NUM_THREADS;
[38374b7]22
23void *PrintHello(void *threadid){
[6fe2cd9]24 long taskid = (long)*threadid; // Dereference rather than direct conv
25
[38374b7]26 //sleep(1);
27 printf("Hello from thread %d\n", taskid);
[6fe2cd9]28 pthread_exit(NULL, false, NULL, 0); //Different parameters
[38374b7]29}
30
[8090425]31int main(void){
[38374b7]32 pthread_t threads[NUM_THREADS];
33 int rc;
34 long t;
35
36 for(t=0;t<NUM_THREADS;t++) {
37 printf("Creating thread %d\n", t);
38 rc = pthread_create(&threads[t], NULL, PrintHello, (void *)&t);
39 if (rc) {
[ca52517]40 $assert(false, "ERROR; return code from pthread_create() is %d", rc);
41 return 0;
[38374b7]42 }
43 }
[6fe2cd9]44 pthread_exit(NULL,true, threads, NUM_THREADS); //Different parameters
[38374b7]45 return 0;
46}
47
Note: See TracBrowser for help on using the repository browser.