summaryrefslogtreecommitdiff
path: root/tests/semaphore3.c
diff options
context:
space:
mode:
authorrpj <rpj>2004-11-03 01:08:41 +0000
committerrpj <rpj>2004-11-03 01:08:41 +0000
commitec8290acdaea21b16d98f1ef5d4ae8a28ab2109a (patch)
tree0bd3750ec1cc12594b6cfe69473e393da6ec101b /tests/semaphore3.c
parentcccaf0c2c82e78a72d69a4a50c872f308bed2f65 (diff)
Mutex, semaphore, thread ID, test suite changes - see ChangeLogs
Diffstat (limited to 'tests/semaphore3.c')
-rw-r--r--tests/semaphore3.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/tests/semaphore3.c b/tests/semaphore3.c
index c6570f8..1b19494 100644
--- a/tests/semaphore3.c
+++ b/tests/semaphore3.c
@@ -80,9 +80,8 @@ sem_t s;
void *
thr (void * arg)
{
- assert(pthread_detach(pthread_self()) == 0);
assert(sem_wait(&s) == 0);
-
+ assert(pthread_detach(pthread_self()) == 0);
return NULL;
}
@@ -91,19 +90,21 @@ main()
{
int value = 0;
int i;
- pthread_t t[MAX_COUNT];
+ pthread_t t[MAX_COUNT+1];
- assert(sem_init(&s, PTHREAD_PROCESS_PRIVATE, 0) == 0);
+ assert(sem_init(&s, PTHREAD_PROCESS_PRIVATE, 0) == 0);
assert(sem_getvalue(&s, &value) == 0);
+// printf("Value = %d\n", value); fflush(stdout);
assert(value == 0);
-// printf("Value = %ld\n", value);
for (i = 1; i <= MAX_COUNT; i++)
{
- assert(pthread_create(&t[i-1], NULL, thr, NULL) == 0);
- sched_yield();
- assert(sem_getvalue(&s, &value) == 0);
-// printf("Value = %ld\n", value);
+ assert(pthread_create(&t[i], NULL, thr, NULL) == 0);
+ do {
+ sched_yield();
+ assert(sem_getvalue(&s, &value) == 0);
+ } while (value != -i);
+// printf("Value = %d\n", value); fflush(stdout);
assert(-value == i);
}
@@ -111,7 +112,7 @@ main()
{
assert(sem_post(&s) == 0);
assert(sem_getvalue(&s, &value) == 0);
-// printf("Value = %ld\n", value);
+// printf("Value = %d\n", value); fflush(stdout);
assert(-value == i);
}