Build a test program for testing TLS support

This commit is contained in:
Martin Storsjö committed 2017-12-04 13:53:44 +02:00
1 parent 634ae81950
commit edcf22bec4
2 files changed
+43 -1

No files matched your search

+6 -1
View File
@@ -250,7 +250,7 @@ RUN cd libcxx && \
RUN cd $TOOLCHAIN_PREFIX/include && ln -s ../$(echo $TOOLCHAIN_ARCHS | awk '{print $1}')-w64-mingw32/include/c++ .
COPY hello.c hello.cpp hello-exception.cpp /build/hello/
COPY hello.c hello.cpp hello-exception.cpp hello-tls.c /build/hello/
RUN cd hello && \
for arch in $TOOLCHAIN_ARCHS; do \
$arch-w64-mingw32-clang hello.c -o hello-$arch.exe || exit 1; \
@@ -266,6 +266,11 @@ RUN cd hello && \
$arch-w64-mingw32-clang++ hello-exception.cpp -o hello-exception-$arch.exe || exit 1; \
done
RUN cd hello && \
for arch in $TOOLCHAIN_ARCHS; do \
$arch-w64-mingw32-clang hello-tls.c -o hello-tls-$arch.exe || exit 1; \
done
ENV AR=llvm-ar
ENV RANLIB=llvm-ranlib
ENV AS=llvm-as
+37
View File
@@ -0,0 +1,37 @@
#include <windows.h>
#include <stdio.h>
#include <process.h>
#if defined(_MSC_VER)
static __declspec(thread) int tlsvar = 1;
#else
static __thread int tlsvar = 1;
#endif
static unsigned __stdcall threadfunc(void* arg) {
int id = (int)arg;
printf("thread %d, tlsvar %p %d\n", id, &tlsvar, tlsvar);
tlsvar = id + 100;
for (int i = 0; i < 5; i++) {
printf("thread %d, tlsvar %p %d\n", id, &tlsvar, tlsvar);
tlsvar += 10;
Sleep(1000);
}
return 0;
}
int main(int argc, char* argv[]) {
HANDLE threads[5];
for (int i = 0; i < 5; i++) {
printf("mainthread, tlsvar %p %d\n", &tlsvar, tlsvar);
tlsvar += 10;
threads[i] = (HANDLE)_beginthreadex(NULL, 0, threadfunc, (void*)(intptr_t) (i + 1), 0, NULL);
Sleep(750);
}
for (int i = 0; i < 5; i++) {
WaitForSingleObject(threads[i], INFINITE);
CloseHandle(threads[i]);
}
return 0;
}