OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libmudflap/] [testsuite/] [libmudflap.cth/] [pass39-frag.c] - Blame information for rev 21

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
#include <stdlib.h>
2
#include <stdio.h>
3
#include <pthread.h>
4
#include <sched.h>
5
#include <assert.h>
6
 
7
static void *
8
func (void *p)
9
{
10
  int *counter = (int *) p;
11
  unsigned i;
12
  enum { numarrays = 100, numels = 17 };
13
  char *arrays [numarrays];
14
 
15
  for (i=0; i<numarrays; i++)
16
    {
17
      (*counter) ++;
18
      unsigned x = i % numels;
19
      arrays[i] = calloc (numels, sizeof(arrays[i][0]));
20
      assert (arrays[i] != NULL);
21
      arrays[i][x] = i;
22
      free (arrays[i]);
23
      sched_yield (); /* sleep (1); */
24
    }
25
 
26
  return (NULL);
27
}
28
 
29
 
30
int main ()
31
{
32
  int rc;
33
  unsigned i;
34
  enum foo { NT=10 };
35
  pthread_t threads[NT];
36
  int counts[NT];
37
 
38
 
39
  for (i=0; i<NT; i++)
40
    {
41
      counts[i] = 0;
42
      rc = pthread_create (& threads[i], NULL, func, (void *) & counts[i]);
43
      if (rc) abort();
44
    }
45
 
46
  for (i=0; i<NT; i++)
47
    {
48
      rc = pthread_join (threads[i], NULL);
49
      if (rc) abort();
50
     printf ("%d%s", counts[i], (i==NT-1) ? "\n" : " ");
51
    }
52
 
53
  return 0;
54
}
55
/* { dg-output "100 100 100 100 100 100 100 100 100 100" } */
56
/* { dg-repetitions 20 } */
57
/* { dg-timeout 10 } */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.