Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <Windows.h>
- #include <thread>
- DWORD WINAPI vaiThread(LPVOID args) {
- Sleep(5000);//o codigo pára apenas neste processo, o outro continua a executar
- static int repeticoes=0;
- int* value = reinterpret_cast<int*>(args);
- printf("\n no thread %d", *value);
- if(!repeticoes) {
- vaiThread(value);//vamos repetir esta parte
- }
- repeticoes++;
- return 1;
- }
- DWORD WINAPI runThread(LPVOID args)
- {
- int* value = reinterpret_cast<int*>(args);
- printf("\n in thread %d", *value);
- return 1;
- }
- int main()
- {
- DWORD threadId;
- DWORD idthread;
- int valor=5;
- int value = 10;
- HANDLE hThread[2];
- hThread[0] = CreateThread( NULL, 0, vaiThread, &valor, 0, &idthread);//cria um processo
- hThread[1] = CreateThread( NULL, 0, runThread, &value, 0, &threadId);//cira outro processo
- Sleep(11000);//os dois processo foram executados, entao vamos para o processo atual para ver o resultado dos outros
- CloseHandle(hThread[0]);
- CloseHandle(hThread[1]);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement