|
|
#1 |
|
Prospect
Join Date: May 2009
Posts: 2
|
OS X semaphore irregularities
Hi all,
I have some very basic semaphore code that works great on Linux, but cannot for the life of me get it to run properly on OS X... It returns the oddest of results... Code:
#include <iostream>
#include <fcntl.h>
#include <stdio.h>
#include <semaphore.h>
int main()
{
sem_t* test;
test = sem_open("test", O_CREAT, 0, 1);
int value;
sem_getvalue(test, &value);
printf("Semaphore initialized to %d\n", value);
}
Code:
iQudsi:Desktop mqudsi$ g++ test.cpp iQudsi:Desktop mqudsi$ ./a.out Semaphore initialized to -1881139893 Code:
iQudsi: Desktop mqudsi$ g++ test.cpp -lrt iQudsi:Desktop mqudsi$ ./a.out Semaphore initialized to 1 I've tried using file paths as the semaphore name, it didn't make a difference. |
|
|
|
|
|
#2 |
|
Moderator
Join Date: Jan 2002
Location: Montreal
Posts: 29,448
|
Try instead this program (which checks for errors):
Code:
#include <iostream>
#include <fcntl.h>
#include <stdio.h>
#include <semaphore.h>
int main()
{
sem_t* test;
test = sem_open("test", O_CREAT, 0, 1);
if (test == SEM_FAILED)
{
perror("sem_open");
}
int value;
if (sem_getvalue(test, &value) != 0)
{
perror("sem_getvalue");
}
printf("Semaphore initialized to %d\n", value);
return 0;
}
__________________
hayne.net/macosx.html |
|
|
|
|
|
#3 |
|
Prospect
Join Date: May 2009
Posts: 2
|
Thanks.
It turns out (despite how much ADC talks about it) sem_getvalue is not implemented on OS X. |
|
|
|
![]() |
| Tags |
| os x, posix, semaphore |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|