Je voulais savoir si le code suivant etait thread safe ou bien si je suis oblige de passer les initialisations des statiques en variables globales :
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 void test(int connectionsNb) { static bool dbPoolInitialized = false; static pthread_mutex_t poolMutex = PTHREAD_MUTEX_INITIALIZER; int iConnection = 0; LOCK(&poolMutex); if (!dbPoolInitialized) { ... dbPoolInitialized = true; } UNLOCK(&poolMutex); }
Partager