dietlibc 0.32 and TLS
Vesna Smiljkovic <[email protected]> Fri, 12 Nov 2010 12:29:32 +0100
| Newsgroups | gmane.linux.lib.dietlibc |
|---|---|
| Message-ID | <[email protected]> |
Hi,
Although dietlibc-0.32 supports TLS, my simple example with thread local
variable does not work properly.
Code of the example:
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
__thread int counter = 0;
void *thread_function() {
printf("thread_function: pointer = %p\n", &counter);
return NULL;
}
int main() {
pthread_t* threads;
if ((threads = (pthread_t *)malloc(sizeof(pthread_t))) == NULL) {
exit(1);
}
if (pthread_create(&threads[0], NULL, thread_function, NULL) != 0) {
exit(1);
}
if (pthread_join(threads[0], NULL) != 0) {
exit(1);
}
printf("Main: pointer = %p\n", &counter);
return 0;
}
According to the execution output:
thread_function: pointer = 0x7fff0c87d1b4
Main: pointer = 0x7fff0c87d1b4
created thread is using the same variable as main thread, without
creating a local copy. Am I missing something in my code or compilation?
Best regards,
Vesna
WARNING / LEGAL TEXT: This message is intended only for the use of the
individual or entity to which it is addressed and may contain
information which is privileged, confidential, proprietary, or exempt
from disclosure under applicable law. If you are not the intended
recipient or the person responsible for delivering the message to the
intended recipient, you are strictly prohibited from disclosing,
distributing, copying, or in any way using this message. If you have
received this communication in error, please notify the sender and
destroy and delete any copies you may have received.
http://www.bsc.es/disclaimer.htm