Last active
October 6, 2019 08:13
-
-
Save msizanoen1/f47d174334c07dcebe615c6d09c291ed to your computer and use it in GitHub Desktop.
Android pthread TLS repro
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
#include <stdio.h> | |
#include <pthread.h> | |
#include <malloc.h> | |
pthread_key_t key; | |
extern int getX(); | |
int main() { | |
key = pthread_key_create(&key, NULL); | |
int *x = (int *)malloc(sizeof(int)); | |
pthread_setspecific(key, x); | |
*x = 1234; | |
printf("%d\n", getX()); | |
} |
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
#include <pthread.h> | |
#include <stdio.h> | |
extern pthread_key_t key; | |
int getX() { | |
int *x = (int *)pthread_getspecific(key); | |
if (x == NULL) { | |
printf("ERROR\n"); | |
return 0; | |
} else { | |
printf("OK"); | |
return *x; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment