Annotation of mstools/samples/tls/tlscall.c, revision 1.1

1.1     ! root        1: #include <stdio.h>
        !             2: #include <stdlib.h>
        !             3: #include <stdarg.h>
        !             4: #include <windows.h>
        !             5: #include <string.h>
        !             6: #include <winbase.h>
        !             7: #include "tlsdll.h"
        !             8: 
        !             9: #define NUMTHREADS 3    /* The number of threads to start */
        !            10: 
        !            11: /*-----------------------------------------------------------------*/
        !            12: 
        !            13: void ErrorOut(char errstring[30])
        !            14: /*
        !            15: Purpose: Print out an meainful error code by means of
        !            16:          GetLastError and printf
        !            17: 
        !            18: Inputs:  errstring - the action that failed, passed by the
        !            19:                      calling proc.
        !            20: 
        !            21: Returns: none
        !            22: 
        !            23: Calls:   GetLastError
        !            24: */
        !            25: 
        !            26: {
        !            27: DWORD Error;
        !            28: 
        !            29: Error= GetLastError();
        !            30: printf("Error on %s = %d\n", errstring, Error);
        !            31: }
        !            32: 
        !            33: /*-----------------------------------------------------------------*/
        !            34: 
        !            35: void Another_Thread()
        !            36: /*
        !            37: Purpose: Make a call into a DLL and then terminate, allowing
        !            38:          DLL init. and termination to be called.
        !            39: 
        !            40: Inputs:  none
        !            41: 
        !            42: Returns: none
        !            43: 
        !            44: Calls:   TlsInit: Dummy proc. to allow DLL initialization.
        !            45: */
        !            46: 
        !            47: {
        !            48: Sleep(300);      /* Sleep while other threads start */
        !            49: TlsInit();       /* Call dummy init. procedure */
        !            50: ExitThread(0);   /* Exit, calling DLL termination */
        !            51: }
        !            52: 
        !            53: /*-----------------------------------------------------------------*/
        !            54: 
        !            55: void main(void)
        !            56: /*
        !            57: Purpose: Make a call into a DLL and then terminate, allowing
        !            58:          DLL init. and termination to be called.
        !            59: 
        !            60: Inputs:  none
        !            61: 
        !            62: Returns: none
        !            63: 
        !            64: Calls:   CreateThread: to create threads for DLL init.
        !            65:          ErrorOut: To output any errors
        !            66:          WaitForMultipleObjects: To wait on thread(s) termination
        !            67: */
        !            68: 
        !            69: {
        !            70: DWORD  threadid;
        !            71: HANDLE hThreads[3];
        !            72: int count;
        !            73: 
        !            74:       /* start NUMTHREADS threads */
        !            75: for (count = 0 ; count < NUMTHREADS ; count++)
        !            76:   {
        !            77:   hThreads[count]= CreateThread(NULL,
        !            78:                                0,
        !            79:                                (LPTHREAD_START_ROUTINE)Another_Thread,
        !            80:                                NULL,
        !            81:                                0,
        !            82:                                &threadid);
        !            83:   if( hThreads[count] == 0)
        !            84:     ErrorOut("CreateThread");
        !            85:   else
        !            86:     printf("\nStarting thread# %d\n\n", count +1);
        !            87:   }
        !            88: 
        !            89:       /* now wait for threads to terminate */
        !            90: printf("\n\n***** Waiting for %d Threads to Exit*****\n\n", NUMTHREADS);
        !            91: WaitForMultipleObjects( NUMTHREADS,
        !            92:                         hThreads,
        !            93:                         FALSE,
        !            94:                         0xFFFFFFFF);
        !            95: Sleep(1000);
        !            96: printf("\n\n*****   All %d Threads Terminated   *****\n\n", NUMTHREADS);
        !            97: 
        !            98: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.