1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
#include <windows.h>
#include <stdio.h>
int m_thread1_on_run;
int m_thread2_on_run;
static DWORD WINAPI FunctionForThread1( void *Param )
{
while(m_thread1_on_run)
{
fprintf(stdout, "Thread 1\n");
// ::Sleep(200); // <--- UTILITE???
}
return 0;
}
static DWORD WINAPI FunctionForThread2( void *Param )
{
while(m_thread2_on_run)
{
fprintf(stdout, "Thread 2\n");
// ::Sleep(200); // <--- UTILITE???
}
return 0;
}
int main(int argc, char*argv[])
{
m_thread1_on_run = true;
m_thread2_on_run = true;
HANDLE m_h_thread1 = ::CreateThread( NULL, 0, FunctionForThread1, NULL, 0, NULL );
HANDLE m_h_thread2 = ::CreateThread( NULL, 0, FunctionForThread2, NULL, 0, NULL );
::Sleep(5000);
m_thread1_on_run = false;
m_thread2_on_run = false;
::WaitForSingleObject(m_h_thread1, INFINITE);
::WaitForSingleObject(m_h_thread2, INFINITE);
return EXIT_SUCCESS;
} |
Partager