◐ Shell
clean mode source ↗

std::thread::native_handle - cppreference.com

Da cppreference.com.

Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.

La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui.

Click here for the English version of this page

<metanoindex/>

<tbody> </tbody>

native_handle_type native_handle();

(dal C++11)

Restituisce l'implementazione definita maniglia sottostante filo.

Original:

Returns the implementation defined underlying thread handle.

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Parametri

(Nessuno)

Original:

(none)

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Valore di ritorno

attuazione definito tipo di handle che rappresenta il filo.

Original:

implementation defined handle type representing the thread.

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Eccezioni

(Nessuno)

Original:

(none)

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Esempio

Utilizza native_handle per abilitare la programmazione in tempo reale di C + + le discussioni su un sistema POSIX

Original:

Uses native_handle to enable realtime scheduling of C++ threads on a POSIX system

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <thread>
#include <iostream>
#include <chrono>
#include <cstring>
#include <pthread.h>

std::mutex iomutex;
void f(int num)
{
    std::this_thread::sleep_for(std::chrono::seconds(1));

   sched_param sch;
   int policy; 
   pthread_getschedparam(pthread_self(), &policy, &sch);
   std::lock_guard<std::mutex> lk(iomutex);
   std::cout << "Thread " << num << " is executing at priority "
             << sch.sched_priority << '\n';
}

int main()
{
    std::thread t1(f, 1), t2(f, 2);

    sched_param sch;
    int policy; 
    pthread_getschedparam(t1.native_handle(), &policy, &sch);
    sch.sched_priority = 20;
    if(pthread_setschedparam(t1.native_handle(), SCHED_FIFO, &sch)) {
        std::cout << "Failed to setschedparam: " << std::strerror(errno) << '\n';
    }

    t1.join(); t2.join();
}

Output:

Thread 2 is executing at priority 0
Thread 1 is executing at priority 20