Bonjour,

j'ai un petit souci avec mes sémaphores POSIX.
Je tente de limiter l'accés à un fichier mais je n'ai pas l'impression que ça marche.
Les sémaphores étant créés avec les droits 0700.
Voici un bout de code.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
Semaphore maSemaphore = Semaphore();
maSemaphore.P();
cout << int_to_str(getpid()) << " j'ai la main" << endl;
ofstream f("test.txt" , ios_base::out | ios_base::app);
f << int_to_str(getpid()) << " - j'écris" << endl;
sleep(10);
f << int_to_str(getpid()) << " - je réécris" << endl;
f.close();
maSemaphore.V();
 
// P()
void Semaphore::P(){
     struct sembuf buffer = {0, -1, 0};//numéro,opération,flag 0,-1,0
     semop(_idSem, &buffer , 1);
}
 
// V()
void Semaphore::V(){
     struct sembuf buffer = {0, 1, 0};
     semop(_idSem, &buffer, 1);
}
Lorsque je fais un ipcs -s le sémaphore est bien créé.

Quelqu'un aurait une piste?