TracktionEngine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
engine::ScopedThreadExitStatusEnabler Struct Reference

Enables the calling thread to be cancelled from another thread and the calling thread to be able to query this. More...

#include <tracktion_Threads.h>

Public Member Functions

 ScopedThreadExitStatusEnabler ()
 Enables the current thread to query shouldCurrentThreadExit and other threads to call signalThreadShouldExit.
 
 ScopedThreadExitStatusEnabler (std::thread::id)
 As above, but registers the given thread rather than the calling one.
 
 ~ScopedThreadExitStatusEnabler ()
 Cleans up the exit status.
 
std::thread::id getID () const
 Returns the thread_id.
 

Detailed Description

Enables the calling thread to be cancelled from another thread and the calling thread to be able to query this.

Put one of these in your thread body then you can use signalThreadShouldExit and shouldCurrentThreadExit

std::thread t ([]
{
for (;;)
{
break;
// Some work...
}
});
t.join();
bool shouldCurrentThreadExit()
Returns true if the current thread is waiting to exit.
void signalThreadShouldExit(std::thread::id)
Can be used to signal that the current thread is waiting to exit.
Enables the calling thread to be cancelled from another thread and the calling thread to be able to q...
Definition tracktion_engine/utilities/tracktion_Threads.h:45

Constructor & Destructor Documentation

◆ ScopedThreadExitStatusEnabler() [1/2]

engine::ScopedThreadExitStatusEnabler::ScopedThreadExitStatusEnabler ( )

Enables the current thread to query shouldCurrentThreadExit and other threads to call signalThreadShouldExit.

◆ ScopedThreadExitStatusEnabler() [2/2]

engine::ScopedThreadExitStatusEnabler::ScopedThreadExitStatusEnabler ( std::thread::id  )
explicit

As above, but registers the given thread rather than the calling one.

Use this from a controlling thread straight after creating the thread, so the registration exists for the thread's whole lifetime by construction: it can then be signalled at any point up to the join with no possibility of the registration not having appeared yet or having already gone. Destroy this after joining the thread.

◆ ~ScopedThreadExitStatusEnabler()

engine::ScopedThreadExitStatusEnabler::~ScopedThreadExitStatusEnabler ( )

Cleans up the exit status.

Member Function Documentation

◆ getID()

std::thread::id engine::ScopedThreadExitStatusEnabler::getID ( ) const

Returns the thread_id.


The documentation for this struct was generated from the following file: