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

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

unix.superglobalmegacorp.com

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