7 ServiceHandler
[NUM_SERVICES
] = {
15 INT ServicePort
[NUM_SERVICES
] = {
23 int main(int argc
, char *argv
[])
25 PSERVICES pServices
[NUM_SERVICES
];
26 DWORD dwThreadId
[NUM_SERVICES
];
27 HANDLE hThread
[NUM_SERVICES
];
30 /* Create MAX_THREADS worker threads. */
31 for( i
=0; i
<NUM_SERVICES
; i
++ )
33 /* Allocate memory for thread data. */
34 pServices
[i
] = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(SERVICES
));
36 if( pServices
[i
] == NULL
)
39 /* Generate unique data for each thread. */
40 pServices
[i
]->Service
= ServiceHandler
[i
];
41 pServices
[i
]->Port
= ServicePort
[i
];
43 hThread
[i
] = CreateThread(
44 NULL
, // default security attributes
45 0, // use default stack size
46 StartServer
, // thread function
47 pServices
[i
], // argument to thread function
48 0, // use default creation flags
49 &dwThreadId
[i
]); // returns the thread identifier
51 /* Check the return value for success. */
52 if (hThread
[i
] == NULL
)
58 /* Wait until all threads have terminated. */
59 WaitForMultipleObjects(NUM_SERVICES
, hThread
, TRUE
, INFINITE
);
61 /* Close all thread handles upon completion. */
62 for(i
=0; i
<NUM_SERVICES
; i
++)
64 CloseHandle(hThread
[i
]);