Qualcuno può mostrare un semplice ma completo esempio di come utilizzare la libreria di eccezioni Boost per trasferire le eccezioni tra thread modificando il codice seguente?Esempio di codice C++ Boost di lancio di un'eccezione tra i thread
Quello che sto implementando è un semplice pattern Delegate multi-thread.
class DelegeeThread
{
public:
void operator()()
{
while(true)
{
// Do some work
if(error)
{
// This exception must be caught by DelegatorThread
throw std::exception("An error happened!");
}
}
}
};
class DelegatorThread
{
public:
DelegatorThread() : delegeeThread(DelegeeThread()){} // launches DelegeeThread
void operator()()
{
while(true)
{
// Do some work and wait
// ? What do I put in here to catch the exception thrown by DelegeeThread ?
}
}
private:
tbb::tbb_thread delegeeThread;
};
wow ... 10 ore dopo il post, e nessuno ha dato una risposta? ho pronunciato male la mia domanda, o questo problema è difficile? – sivabudh
Vorrei ricordare che qualunque cosa tu finisca per implementare potrebbe non essere quello che ti aspetti. quando DelegeeThread vuole attivare un'eccezione nell'altro thread, il Delegator eseguirà probabilmente del lavoro non correlato o potrebbe essere già terminato, quindi il problema potrebbe essere ritardato o non avvenire affatto. – asveikau
sicuro, il punto che hai citato, sono d'accordo. – sivabudh