2016-05-03 27 views
0

sem_openを使用してセマフォを1に初期化しようとしていますが、動作させることができません。セマフォが初期化されていません

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); 

私は、コードを実行すると、出力は次のとおりです。

The initial value of sem_Montague is 0 

それは1でなければなりませんし、私はそれが適切に初期化していない理由はわかりません。

+0

私は自分のシステムで1を取得します...どのコンパイラ/ツールチェーンを使用していますか?どのプラットフォームですか? – bodangly

+0

OS Yosemiteをg ++コンパイラで使用しています。 g ++でコンパイルする-ipthread verona.cpp -o verona – Clopen

+0

Macについて興味深いことに、g ++はしばしば静かにエイリアスになってしまいます。 – user4581301

答えて

1

私はsem_getvalueがOS X用に実装されているとは思いません。私はそのスタブだと思います。

関連する問題