Re: Anything wrong with x86_64 and SYSV shared memory allocation?
site_archiver@lists.apple.com Delivered-To: darwin-kernel@lists.apple.com -- Terry Actually, this seems to be incorrect: #include <semaphore.h> #include <stdio.h> int main() { sem_t *sem1, *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; 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 (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/tlambert%40apple.com _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/site_archiver%40lists.a... You end up with a different semaphore; that's what I meant by "fail". The unlink destroys the namespace entry for it. On May 10, 2007, at 2:39 AM, Jonas Maebe wrote: 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. 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"); } 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"); } This email sent to tlambert@apple.com This email sent to site_archiver@lists.apple.com
participants (1)
-
Terry Lambert