0
Ich versuche, mein Semaphor auf 1 mit sem_open zu initialisieren, aber ich kann nicht scheinen, es zu arbeiten.Semaphor nicht initialisiert
sem_t *Montague, *Capulet; // the two semaphores
char sem_Montague[]= "jud_Montague"; // their names
char sem_Capulet[]= "jud_Capulet"; // their names
int semvalue; // stores value returned by sem_getvalue()
Montague = sem_open(sem_Montague, O_CREAT, 0600, 1);
// We specify that the semaphore should be created it it did
// not exist already, prevent other users from accessing it
// (0600) and set its initial value to one
if (Montague == SEM_FAILED) {
perror("unable to create Montague semaphore");
sem_unlink(sem_Montague);
exit(1);
} // if
// Just to show that we can test the value of a semaphore
sem_getvalue(Montague, &semvalue);
printf("The initial value of sem_Montague is %d\n", semvalue);
Wenn ich den Code ausführen, ist die Ausgabe:
The initial value of sem_Montague is 0
Es sollte 1 und ich bin nicht sicher, warum es nicht richtig ist initialisiert.
Ich bekomme 1 auf meinem System ... welche Compiler/Tool-Kette benutzen Sie? Welche Plattform? – bodangly
Ich benutze OS Yosemite mit einem g ++ Compiler. Kompiliert mit g ++ -ipthread verona.cpp -o verona – Clopen
Interessant an einem Mac, g ++ wird oft still Aliasing zu Clang. – user4581301