Re: Anything wrong with x86_64 and SYSV shared memory allocation?
Re: Anything wrong with x86_64 and SYSV shared memory allocation?
- Subject: Re: Anything wrong with x86_64 and SYSV shared memory allocation?
- From: Jonas Maebe <email@hidden>
- Date: Thu, 10 May 2007 11:39:51 +0200
On 24 apr 2007, at 14:47, Terry Lambert wrote:
Of course, POSIX semaphores can be forced to be resource tracked
using sem_unlink() after the last sem_open(), but once they are
unlinked, subsequent sem_open()'s fail until everyone has drained
out their references through either _exit() or sem_close(), so they
are more or less in the same boat.
Actually, this seems to be incorrect:
#include <semaphore.h>
#include <stdio.h>
int main() {
sem_t *sem1, *sem2;
sem1 = sem_open("/mysemtest1",O_CREAT|O_EXCL,0,0);
if (sem1 == (sem_t*)SEM_FAILED) {
printf("Failed to create sem1\n");
return 1;
}
sem2 = sem_open("/mysemtest1",O_CREAT|O_EXCL,0,0);
if (sem2 == (sem_t*)SEM_FAILED) {
printf("sem2 with same name as sem1 failed before unlink\n");
} else {
printf("sem2(%d) with same name as sem1(%d) succeeded before
unlink\n",(int)sem2,(int)sem1);
}
if (sem_unlink("/mysemtest1")) {
perror("failed unlinking sem1");
}
sem2 = sem_open("/mysemtest1",O_CREAT|O_EXCL,0,0);
if (sem2 == (sem_t*)SEM_FAILED) {
printf("sem2 with same name as sem1 failed after unlink\n");
} else {
printf("sem2(%d) with same name as sem1(%d) succeeded after
unlink\n",(int)sem2,(int)sem1);
}
if (sem_unlink("/mysemtest1")) {
perror("failed unlinking sem2");
}
if (sem_close(sem1)) {
perror("failed closing sem1");
}
if (sem_close(sem2)) {
perror("failed closing sem2");
}
}
bigmac:~/fpc/tests/test jonas$ gcc -o tt tt.c
.bigmac:~/fpc/tests/test jonas$ ./tt
sem2 with same name as sem1 failed before unlink
sem2(4) with same name as sem1(3) succeeded after unlink
bigmac:~/fpc/tests/test jonas$
bigmac:~/fpc/tests/test jonas$
bigmac:~/fpc/tests/test jonas$
bigmac:~/fpc/tests/test jonas$
bigmac:~/fpc/tests/test jonas$ cat tt.c
#include <semaphore.h>
#include <stdio.h>
int main() {
sem_t *sem1, *sem2;
sem1 = sem_open("/mysemtest1",O_CREAT|O_EXCL,0,0);
if (sem1 == (sem_t*)SEM_FAILED) {
printf("Failed to create sem1\n");
return 1;
}
sem2 = sem_open("/mysemtest1",O_CREAT|O_EXCL,0,0);
if (sem2 == (sem_t*)SEM_FAILED) {
printf("sem2 with same name as sem1 failed before unlink\n");
} else {
printf("sem2(%d) with same name as sem1(%d) succeeded before
unlink\n",(int)sem2,(int)sem1);
}
if (sem_unlink("/mysemtest1")) {
perror("failed unlinking sem1");
}
sem2 = sem_open("/mysemtest1",O_CREAT|O_EXCL,0,0);
if (sem2 == (sem_t*)SEM_FAILED) {
printf("sem2 with same name as sem1 failed after unlink\n");
} else {
printf("sem2(%d) with same name as sem1(%d) succeeded after
unlink\n",(int)sem2,(int)sem1);
}
if (sem_unlink("/mysemtest1")) {
perror("failed unlinking sem2");
}
if (sem_close(sem1)) {
perror("failed closing sem1");
}
if (sem_close(sem2)) {
perror("failed closing sem2");
}
}
bigmac:~/fpc/tests/test jonas$ gcc -o tt tt.c
bigmac:~/fpc/tests/test jonas$ ./tt
sem2 with same name as sem1 failed before unlink
sem2(4) with same name as sem1(3) succeeded after unlink
bigmac:~/fpc/tests/test jonas$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.4.9
BuildVersion: 8P135
Jonas
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden