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

#include <evo/thread.h>

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

Detailed Description

template<>
struct evo::ThreadScope< Thread >

Creates a single thread of execution in given scope.

Example – Function-Based Thread
#include <evo/thread.h>
using namespace evo;
static void thread_run(void* arg) {
// Thread code
}
int main() {
{
// This runs the thread and joins in destructor, arg=NULL
ThreadScope<> thread(thread_run, NULL);
}
return 0;
}

Public Types

typedef std::function< void(void *)> Func
 Thread function type – with C++11 supports lambda/functor, otherwise just function pointer More...
 
typedef ThreadScope< ThreadThis
 

Public Member Functions

 ThreadScope (Thread::Func func, void *arg=NULL)
 Constructor starts thread. More...
 
 ~ThreadScope ()
 Destructor joins thread. More...
 
bool active () const
 Get whether thread is active (running). More...
 
bool detach ()
 Detach thread to run in background. 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...
 
bool thread_active () const
 Get whether thread is active (running). More...
 
virtual bool thread_detach ()
 Detach thread to run in background. More...
 
SysThread::Handle thread_handle () const
 Get platform-specific thread handle. More...
 
bool thread_join ()
 Join thread by waiting for thread to stop. More...
 
bool thread_start ()
 Start thread. More...
 

Static Public Member Functions

static ulong id ()
 Get current thread ID from system. More...
 
static void yield ()
 Yield control to another thread or process. More...
 

Public Attributes

Init thread_init
 Thread function pointer More...
 

Protected Attributes

bool thread_active_
 
SysThread thread_impl_
 

Member Typedef Documentation

◆ Func

typedef std::function<void (void*)> Func
inherited

Thread function type – with C++11 supports lambda/functor, otherwise just function pointer

◆ This

Constructor & Destructor Documentation

◆ ThreadScope()

ThreadScope ( Thread::Func  func,
void *  arg = NULL 
)
inline

Constructor starts thread.

Parameters
funcThread function pointer
argArgument to pass to thread function

◆ ~ThreadScope()

~ThreadScope ( )
inline

Destructor joins thread.

Member Function Documentation

◆ active()

bool active ( ) const
inline

Get whether thread is active (running).

Returns
Whether active

◆ detach()

bool detach ( )
inline

Detach thread to run in background.

  • The thread will continue running and will no longer be joinable or accessible
  • Start a new thread with thread_start()

◆ handle()

SysThread::Handle handle ( ) const
inline

Get platform-specific thread handle.

Returns
Thread handle

◆ id()

static ulong id ( )
inlinestaticinherited

Get current thread ID from system.

Returns
Current thread ID

◆ join()

bool join ( )
inline

Join thread by waiting for thread to stop.

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)

◆ thread_active()

bool thread_active ( ) const
inlineinherited

Get whether thread is active (running).

  • This gets whether the thread was started but hasn't been joined yet – the thread may have terminated though
Returns
Whether active, true if thread has started and hasn't been joined yet

◆ thread_detach()

virtual bool thread_detach ( )
inlinevirtualinherited

Detach thread to run in background.

  • The thread will continue running and will no longer be joinable or accessible
  • Start a new thread with thread_start()

◆ thread_handle()

SysThread::Handle thread_handle ( ) const
inlineinherited

Get platform-specific thread handle.

Returns
Thread handle

◆ thread_join()

bool thread_join ( )
inlineinherited

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

◆ thread_start()

bool thread_start ( )
inlineinherited

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)

◆ yield()

static void yield ( )
inlinestaticinherited

Yield control to another thread or process.

Member Data Documentation

◆ thread_active_

bool thread_active_
protectedinherited

◆ thread_impl_

SysThread thread_impl_
protectedinherited

◆ thread_init

Init thread_init
inherited

Thread function pointer


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