Evo C++ Library v0.5.1
Public Types | Public Member Functions | List of all members
ThreadScope< T > Struct Template Reference

#include <evo/thread.h>

Inheritance diagram for ThreadScope< T >:
Inheritance graph
[legend]

Detailed Description

template<class T = Thread>
struct evo::ThreadScope< T >

Creates a single thread of execution in given scope.

Template Parameters
TThread type: Thread for function-based thread (default), or type derived from ThreadClass for class-based thread
Example – Class-Based Thread
#include <evo/thread.h>
using namespace evo;
class MyThread : public ThreadClass {
public:
void thread_run() {
// Thread code
}
};
int main() {
{
// This runs the thread and joins in destructor
}
return 0;
}

Public Types

typedef ThreadScope< T > This
 Current ThreadScope. More...
 

Public Member Functions

 ThreadScope ()
 Constructor starts thread. More...
 
 ~ThreadScope ()
 Destructor cancels and joins thread. More...
 
bool active () const
 Get whether thread is active (running). More...
 
Thiscancel (bool locked=false)
 Set cancel flag to signal thread to stop, and wake thread via condition object. More...
 
bool cancel_join (bool locked=false)
 Cancels and joins thread. More...
 
SysThread::Handle handle () const
 Get platform-specific thread handle. More...
 
bool join ()
 Join thread by waiting for thread to stop. More...
 
bool start ()
 Start thread. More...
 

Member Typedef Documentation

◆ This

typedef ThreadScope<T> This

Current ThreadScope.

Constructor & Destructor Documentation

◆ ThreadScope()

ThreadScope ( )
inline

Constructor starts thread.

◆ ~ThreadScope()

~ThreadScope ( )
inline

Destructor cancels and joins thread.

Member Function Documentation

◆ active()

bool active ( ) const
inline

Get whether thread is active (running).

Returns
Whether active

◆ cancel()

This& cancel ( bool  locked = false)
inline

Set cancel flag to signal thread to stop, and wake thread via condition object.

  • Cancellation is not enforced, the thread has to call cancel_check() regularly to check if it's been cancelled
  • After setting cancel flag, this notifies on condmutex to wake thread
  • This always unlocks condmutex when done
Parameters
lockedWhether condmutex object is already locked
Returns
This

◆ cancel_join()

bool cancel_join ( bool  locked = false)
inline

Cancels and joins thread.

Parameters
lockedPassed to thread_cancel(): Whether condmutex object is already locked
Returns
Whether successful, false on error (out of memory/resources) or if thread not started

◆ handle()

SysThread::Handle handle ( ) const
inline

Get platform-specific thread handle.

Returns
Thread handle

◆ join()

bool join ( )
inline

Join thread by waiting for thread to stop.

  • Class-based thread: May need to call thread_cancel() and wake the thread first, depending on thread implementation
Returns
Whether successful, false on error (out of memory/resources) or if thread not started

◆ start()

bool start ( )
inline

Start thread.

  • The thread will start immediately, possibly even before this returns
Returns
Whether successful, false on error (out of memory/resources or thread_init.func=NULL)

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