-
-
Notifications
You must be signed in to change notification settings - Fork 645
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When sem_wait() used its futexes it would always use process shared mode which can be problematic on platforms like Windows, where that causes it to use the slow futex polyfill. Now when sem_init() is called in private mode that'll be passed along so we can use a faster WaitOnAddress() call
- Loading branch information
Showing
5 changed files
with
76 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <pthread.h> | ||
#include <semaphore.h> | ||
|
||
#define THREADS 10 | ||
#define ITERATIONS 100000 | ||
|
||
int g_count; | ||
sem_t g_sem; | ||
|
||
void *worker(void *arg) { | ||
for (int i = 0; i < ITERATIONS; ++i) { | ||
if (sem_wait(&g_sem)) | ||
exit(6); | ||
++g_count; | ||
if (sem_post(&g_sem)) | ||
exit(7); | ||
} | ||
return 0; | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
pthread_t th[THREADS]; | ||
if (sem_init(&g_sem, 0, 1)) | ||
return 1; | ||
for (int i = 0; i < THREADS; ++i) | ||
if (pthread_create(&th[i], 0, worker, 0)) | ||
return 2; | ||
for (int i = 0; i < THREADS; ++i) | ||
if (pthread_join(th[i], 0)) | ||
return 3; | ||
if (g_count != THREADS * ITERATIONS) | ||
return 4; | ||
if (sem_destroy(&g_sem)) | ||
return 5; | ||
} |