2
/* FIXME: this is basically a bad test as it is scheduling-
3
sensitive. Sometimes the output is:
20
/* Simple test program, no race. Parent writes atomically to a counter
21
whilst child reads it. When counter reaches a prearranged value,
22
child joins back to parent. Parent (writer) uses hardware bus lock;
23
child is only reading and so does not need to use a bus lock. */
27
#undef PLAT_amd64_linux
28
#undef PLAT_ppc32_linux
29
#undef PLAT_ppc64_linux
30
#undef PLAT_ppc32_aix5
31
#undef PLAT_ppc64_aix5
33
#if !defined(_AIX) && defined(__i386__)
34
# define PLAT_x86_linux 1
35
#elif !defined(_AIX) && defined(__x86_64__)
36
# define PLAT_amd64_linux 1
37
#elif !defined(_AIX) && defined(__powerpc__) && !defined(__powerpc64__)
38
# define PLAT_ppc32_linux 1
39
#elif !defined(_AIX) && defined(__powerpc__) && defined(__powerpc64__)
40
# define PLAT_ppc64_linux 1
41
#elif defined(_AIX) && defined(__64BIT__)
42
# define PLAT_ppc64_aix5 1
43
#elif defined(_AIX) && !defined(__64BIT__)
44
# define PLAT_ppc32_aix5 1
47
#if defined(PLAT_amd64_linux) || defined(PLAT_x86_linux)
48
# define INC(_lval,_lqual) \
49
__asm__ __volatile__ ( \
50
"lock ; incl (%0)" : /*out*/ : /*in*/"r"(&(_lval)) : "memory", "cc" )
51
#elif defined(PLAT_ppc32_linux) || defined(PLAT_ppc64_linux) \
52
|| defined(PLAT_ppc32_aix5) || defined(PLAT_ppc64_aix5)
53
# define INC(_lval,_lqual) \
54
__asm__ __volatile__( \
55
"L1xyzzy1" _lqual ":\n" \
59
" bne- L1xyzzy1" _lqual \
60
: /*out*/ : /*in*/ "b"(&(_lval)) \
61
: /*trash*/ "r15", "cr0", "memory" \
64
# error "Fix Me for this platform"
73
void* child_fn ( void* arg )
82
printf("child: new value %d\n", oldx);
86
/* Make sure the parent doesn't starve. Seems to be a problem
87
on very slow machines. */
89
if (ctr == 2000000) sleep(1);
99
if (pthread_create(&child, NULL, child_fn, NULL)) {
100
perror("pthread_create");
104
for (i = 0; i < LIMIT; i++) {
106
if (i == 5) sleep(1); /* make sure child doesn't starve */
109
if (pthread_join(child, NULL)) {
110
perror("pthread join");
114
printf("done, x = %d\n", x);