Grazie!

Codice PHP:
#include <windows.h>
#include <cstdlib>
#include <process.h>
#include <iostream>

unsigned int __stdcall startRecorder(void*);
unsigned int __stdcall stopRecorder(void*);

bool volatile stopThreadFlag false;

int main()
{
    
HANDLE hthread[2]       = {0};
    
unsigned int prodRet[2] = {0};

    
// Launch startRecorder Thread
    //
    
hthread[0] = (HANDLE)_beginthreadex(0,0,startRecorder,0,0,&prodRet[0]);
    if(
prodRet[0])
        
std::cout << "Launched startRecorder Thread!" << std::endl;

    
// Stop previous thread (by launching stopThread)
    // if any key is pressed
    //
    
system("pause");

    
hthread[1] = (HANDLE)_beginthreadex(0,0,stopRecorder,0,0,&prodRet[1]);
    if(
prodRet[1])
        
std::cout << "Launched stopRecorder Thread!" << std::endl;

    
// WaitForMultipleObjects
    //
    
WaitForMultipleObjects(2hthreadtrueINFINITE);

    
CloseHandle(hthread[0]);
    
CloseHandle(hthread[1]);

    
system("pause");
    return 
EXIT_SUCCESS;
}

unsigned int __stdcall startRecorder(void*)
{
    while(
1)
    {
        
Sleep(1000);
        
std::cout << "I am the thread!" << std::endl;

        if(
stopThreadFlag)
            break;
    }
    return 
0;
}

unsigned int __stdcall stopRecorder(void*)
{
    
stopThreadFlag true;
    return 
0;