Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    [C++] _beginthreadex e WaitForSingleObject

    Salve,

    lanciando un thread con questo codice:

    codice:
    unsigned int prodRet;
    _beginthreadex(0,0,startRecorder,NULL,0,&prodRet);
    come faccio per rintracciarne l'handle per poi fare:

    codice:
    WaitForSingleObject(HANDLE, INFINITE)
    ???

    grazie
    Alla batteria dai retta ballA

  2. #2
    Utente di HTML.it L'avatar di Stoicenko
    Registrato dal
    Feb 2004
    Messaggi
    2,254
    devi per forza usare la _beginthreadex?

  3. #3
    assolutamente si
    Alla batteria dai retta ballA

  4. #4

    Re: [C++] _beginthreadex e WaitForSingleObject

    Originariamente inviato da gianvituzzi
    come faccio per rintracciarne l'handle
    ultimo esempio ("crt_begthrdex.cpp") alla:
    http://msdn.microsoft.com/en-us/libr...cb(VS.80).aspx

  5. #5
    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;

    Alla batteria dai retta ballA

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.