2001-04-04 15:30:01

by David Howells

[permalink] [raw]
Subject: rw_semaphore bug

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <fcntl.h>

int main(int argc, char *argv[])
{
int loop, fd, tmp;

fd = open("/proc/rwsem",O_RDWR);
if (fd<0) {
perror("open");
return 1;
}

for (loop=0; loop<50; loop++) {
switch (fork()) {
case -1:
perror("fork");
return 1;
case 0:
write(fd," ",1);
exit(1);
default:
break;
}
}

for (loop=0; loop<5; loop++) {
if (wait(&tmp)<0) {
perror("wait");
return 1;
}
}

return 0;
}