~mysql/mysql-server/mysql-6.0

« back to all changes in this revision

Viewing changes to mit-pthreads/tests/test_preemption_float.c

  • Committer: bk at mysql
  • Date: 2000-07-31 19:29:14 UTC
  • Revision ID: sp1r-bk@work.mysql.com-20000731192914-08846
Import changeset

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Test to see if floating point state is being properly maintained
 
2
   for each thread.  Different threads doing floating point operations
 
3
   simultaneously should not interfere with one another.  This
 
4
   includes operations that might change some FPU flags, such as
 
5
   rounding modes, at least implicitly.  */
 
6
 
 
7
#include <pthread.h>
 
8
#include <math.h>
 
9
#include <stdio.h>
 
10
 
 
11
int limit = 2;
 
12
int float_passed = 0;
 
13
int float_failed = 1;
 
14
 
 
15
void *log_loop (void *x) {
 
16
  int i;
 
17
  double d, d1, d2;
 
18
  /* sleep (1); */
 
19
  for (i = 0; i < limit; i++) {
 
20
    d = 42.0;
 
21
    d = log (exp (d));
 
22
    d = (d + 39.0) / d;
 
23
    if (i == 0)
 
24
      d1 = d;
 
25
    else {
 
26
                d2 = d;
 
27
                d = sin(d);
 
28
                /* if (d2 != d1) { */
 
29
                if (memcmp (&d2, &d1, 8)) {
 
30
                        pthread_exit(&float_failed);
 
31
                }
 
32
        }
 
33
  }
 
34
  pthread_exit(&float_passed);
 
35
}
 
36
 
 
37
void *trig_loop (void *x) {
 
38
  int i;
 
39
  double d, d1, d2;
 
40
  /* sleep (1);  */
 
41
  for (i = 0; i < limit; i++) {
 
42
    d = 35.0;
 
43
    d *= M_PI;
 
44
    d /= M_LN2;
 
45
    d = sin (d);
 
46
    d = cos (1 / d);
 
47
    if (i == 0)
 
48
      d1 = d;
 
49
    else {
 
50
                d2 = d;
 
51
                d = sin(d);
 
52
                /* if (d2 != d1) { */
 
53
                if (memcmp (&d2, &d1, 8)) {
 
54
                        pthread_exit(&float_failed);
 
55
                }
 
56
        }
 
57
  }
 
58
  pthread_exit(&float_passed);
 
59
}
 
60
 
 
61
#define N 10
 
62
int main () {
 
63
  int i;
 
64
  pthread_t thread[2];
 
65
  pthread_attr_t attr;
 
66
  int *x, *y;
 
67
 
 
68
  pthread_init ();
 
69
  pthread_attr_init(&attr);
 
70
  pthread_attr_setfloatstate(&attr, PTHREAD_NOFLOAT);
 
71
 
 
72
  while(limit < 100000) {
 
73
    pthread_create (&thread[0], &attr, trig_loop, 0);
 
74
    pthread_create (&thread[1], &attr, log_loop, 0);
 
75
        pthread_join(thread[0], (void **) &x);  
 
76
        pthread_join(thread[1], (void **) &y);  
 
77
        if ((*x == float_failed) || (*y == float_failed)) {
 
78
                limit *= 4;
 
79
                break;
 
80
        }
 
81
        limit *= 4;
 
82
  }
 
83
  if ((*x == float_passed) && (*y == float_passed)) {
 
84
        printf("test_preemption_float INDETERMINATE\n");
 
85
    return(0);
 
86
  }
 
87
  pthread_create (&thread[0], NULL, trig_loop, 0);
 
88
  pthread_create (&thread[1], NULL, log_loop, 0);
 
89
  pthread_join(thread[0], (void **) &x);        
 
90
  pthread_join(thread[1], (void **) &y);        
 
91
 
 
92
  if ((*x == float_failed) || (*y == float_failed)) {
 
93
        printf("test_preemption_float FAILED\n");
 
94
        return(1);
 
95
  }
 
96
  printf("test_preemption_float PASSED\n");
 
97
  return(0);
 
98
}