DarkWinAPI by Darkleo.com
MultiThreading
#include <windows.h> #include <stdio.h> DWORD WINAPI Client0_Hauptfunktion (LPVOID lpThreadParameter); DWORD WINAPI Client1_Hauptfunktion (LPVOID lpThreadParameter); int main (void) { DWORD dwMasterThreadId, dwClient0_ThreadId, dwClient1_ThreadId; HANDLE Threads[2]; DWORD dwThreadExitCode; dwMasterThreadId = GetCurrentThreadId(); printf("[Thread-ID] -----Ausgabe----- \n\n"); printf("[%08x] Hallo, ich bin der Master-Thread! \n", dwMasterThreadId); Threads[0]=CreateThread(NULL,0,Client0_Hauptfunktion, (LPVOID)10,0, &dwClient0_ThreadId); Threads[1]=CreateThread(NULL,0,Client1_Hauptfunktion, (LPVOID)10,0, &dwClient1_ThreadId); if(Threads[0] != NULL && Threads[1] != NULL) { WaitForMultipleObjects(2, Threads, TRUE, INFINITE); printf("[%08x] Hallo, ich bin der Master-Thread !\n", dwMasterThreadId); Sleep(6000); GetExitCodeThread(Threads[0], &dwThreadExitCode); printf("[%08x] Client0-Thread Exitcode 0x%08x.\n", dwMasterThreadId, dwThreadExitCode); GetExitCodeThread(Threads[1], &dwThreadExitCode); printf("[%08x] Client0-Thread Exitcode 0x%08x.\n", dwMasterThreadId, dwThreadExitCode); CloseHandle(Threads[0]); CloseHandle(Threads[1]); } else { printf("[%08x] Es ist ein Fehler beim erzeugen der Client-Threads aufgetreten: error 0x%x\n", dwMasterThreadId, GetLastError()); } printf("[%08x] Tschüss, Dein multithreaded Hallo!\n", dwMasterThreadId); return 0; } DWORD WINAPI Client0_Hauptfunktion (LPVOID nichtverwendet) { int i; DWORD dwThreadId = GetCurrentThreadId(); for(i=0;i<5;i++) { Sleep(1000); printf("[%08x] Hallo, ich bin der Client0-Thread\n", dwThreadId); } return(dwThreadId); } DWORD WINAPI Client1_Hauptfunktion (LPVOID nichtverwendet) { int i; DWORD dwThreadId = GetCurrentThreadId(); for(i=0;i<5;i++) { Sleep(1000); printf("[%08x] Hallo, ich bin der Client1-Thread\n", dwThreadId); } return(dwThreadId); } |