### _threadstore -- Access Thread-Specific Storage (OS/2)

Format

>     #include <stdlib.h>
>     void *_threadstore(void);

Language Level: Extension
_threadstore provides access to a private thread pointer that is initialized to NULL. You can assign any thread-specific data structure to this pointer.

You can only use _threadstore in multithread programs (compiled with the /Gm+ option).

Return Value
_threadstore returns the address of the pointer to the defined thread storage space.

Example
This example uses _threadstore to point to storage that is local to the thread. It prints the address pointed to by _threadstore.

Note: You must compile this example with the multithread option (/Gm+).

    #if  (1 == __TOS_OS2__)
          #define INCL_DOSPROCESS                 /*  For OS/2  */
          #include <os2.h>
          #define SLEEP  DosSleep(5000L)
    #else
          #include <windows.h>                    /*  For Windows  */
          #define SLEEP  Sleep(5000L)
    #endif

    #include <stdlib.h>
    #include <stdio.h>

    #define  privateStore   (*_threadstore())

    void thread(void *dummy)
    {
       privateStore = malloc(100);
       printf("The starting address of the storaged space is %p\n", privateStore);

       /* user must free storage before exiting thread */
       free (privateStore);
       _endthread();
    }

    int main(void)
    {
       int i;

       for (i = 0; i < 10; i++)
          _beginthread(thread, NULL, (unsigned) 32096, NULL);
       SLEEP;
       return 0;
    }

_beginthread -- Create New Thread
_endthread -- Terminate Current Thread
<stdlib.h>
/Gm compiler option