Last active
March 19, 2020 21:18
-
-
Save nixpulvis/8b143383c4d797858f7b83b5cd53e1da to your computer and use it in GitHub Desktop.
Intel pthreads Issue
This file contains hidden or 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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <pthread.h> | |
static pthread_t thread; | |
static pthread_mutex_t mutex; | |
void* work(void* ptr) | |
{ | |
pthread_detach(pthread_self()); | |
for (;;) { | |
if (pthread_mutex_trylock(&mutex)) | |
continue; | |
printf("thread"); | |
printf("\n"); | |
pthread_mutex_unlock(&mutex); | |
} | |
} | |
int main() | |
{ | |
pthread_mutex_init(&mutex, NULL); | |
pthread_create(&thread, NULL, work, NULL); | |
for (;;) { | |
// XXX: This will cause some systems to segfault. | |
// https://software.intel.com/en-us/forums/intel-isa-extensions/topic/675036 | |
pthread_mutex_unlock(&mutex); | |
if (pthread_mutex_trylock(&mutex)) | |
continue; | |
printf("main"); | |
printf("\n"); | |
pthread_mutex_unlock(&mutex); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment