~bkerensa/ubuntu/raring/valgrind/merge-from-deb

« back to all changes in this revision

Viewing changes to helgrind/tests/tc24_nonzero_sem.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrés Roldán
  • Date: 2008-06-13 02:31:40 UTC
  • mto: (1.4.1 upstream) (2.2.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: james.westby@ubuntu.com-20080613023140-iwk33rz9rhvfkr96
Import upstream version 3.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/* Check that Helgrind does not complain about semaphores with a
 
3
   nonzero initial value, when said semaphores are correctly used.
 
4
   Also useful for generating VCG of simple semaphore activity, for
 
5
   inspection. */
 
6
 
 
7
#include <pthread.h>
 
8
#include <semaphore.h>
 
9
#include <assert.h>
 
10
 
 
11
#define N_THREADS 3
 
12
 
 
13
void* child_fn ( void* semV )
 
14
{
 
15
   int r;
 
16
   sem_t* sem = (sem_t*)semV;
 
17
   r= sem_wait(sem); assert(!r);
 
18
   return NULL;
 
19
}
 
20
 
 
21
int main ( void )
 
22
{
 
23
   int r, i;
 
24
   sem_t sem;
 
25
   pthread_t child[N_THREADS];
 
26
 
 
27
   r= sem_init(&sem, 0, N_THREADS); assert(!r);
 
28
 
 
29
   for (i = 0; i < N_THREADS; i++) {
 
30
      r= pthread_create( &child[i], NULL, child_fn, (void*)&sem );
 
31
      assert(!r);
 
32
   }
 
33
 
 
34
   for (i = 0; i < N_THREADS; i++) {
 
35
      r= pthread_join( child[i], NULL );
 
36
      assert(!r);
 
37
   }
 
38
 
 
39
   sem_destroy(&sem);
 
40
   return 0;
 
41
}