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