Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented Thread Local Storage support.
This is still rough, but the basic idea seems to work!
- Loading branch information
Showing
6 changed files
with
277 additions
and
7 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,54 @@ | ||
#define INCL_DOS | ||
#define INCL_DOSERRORS | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <os2.h> | ||
|
||
static PULONG GAddr = NULL; | ||
static ULONG x = 0; | ||
|
||
static void APIENTRY threadFunc(ULONG arg) | ||
{ | ||
const unsigned int t = (unsigned int) arg; | ||
DosSleep(t == 1 ? 500 : 1000); | ||
*GAddr = t * 100; | ||
//printf("thread %u set TLS value to %u\n", t, t * 100); | ||
//fflush(stdout); | ||
DosSleep(t == 1 ? 1000 : 50); | ||
x = *GAddr; | ||
//printf("thread %u sees TLS value of %u\n", t, (unsigned int) *GAddr); | ||
//fflush(stdout); | ||
} | ||
|
||
int main(void) | ||
{ | ||
TID tid = 0; | ||
|
||
if (DosAllocThreadLocalMemory(1, &GAddr) != NO_ERROR) { | ||
fprintf(stderr, "DosAllocLocalThreadMemory failed\n"); | ||
return 1; | ||
} | ||
printf("the magic address is %p\n", GAddr); | ||
*GAddr = 10; | ||
printf("Main thread set TLS value to 10\n"); | ||
fflush(stdout); | ||
|
||
if (DosCreateThread(&tid, threadFunc, 1, 0, 0xFFFF) != NO_ERROR) { | ||
fprintf(stderr, "DosCreateThread 1 failed\n"); | ||
return 1; | ||
} | ||
if (DosCreateThread(&tid, threadFunc, 2, 0, 0xFFFF) != NO_ERROR) { | ||
fprintf(stderr, "DosCreateThread 2 failed\n"); | ||
return 1; | ||
} | ||
|
||
DosSleep(4000); | ||
|
||
printf("Main thread sees TLS value of %u\n", (unsigned int) *GAddr); | ||
fflush(stdout); | ||
|
||
DosFreeThreadLocalMemory(GAddr); | ||
|
||
return 0; | ||
} | ||
|
Binary file not shown.