Proud::Thread Class Reference

Public Types

typedef void(* ThreadProc )(void *ctx)
 

Public Member Functions

PROUD_API Thread (ThreadProc threadProc, void *ctx, bool neededJoin=true)
 
PROUD_API ~Thread ()
 
PROUD_API void Start ()
 
PROUD_API void Join ()
 
 __declspec (property(get=GetHandle)) HANDLE Handle
 
HANDLE GetHandle ()
 
 __declspec (property(get=GetID)) uint64_t ID
 
uint64_t GetID ()
 
bool IsAlive () const
 

Static Public Member Functions

static PROUD_API void NotifyDllProcessDetached ()
 

Public Attributes

bool m_useComModel
 

Static Public Attributes

static bool m_dllProcessDetached_INTERNAL
 

Friends

class ThreadProcContext
 

Detailed Description

Simple thread wrapper class

  • After creating this instance, a thread will be created by calling Start. And if this instance is destructed then it will be blocked until created thread is terminated.
  • This class has the same operating process as System.Threading.Thread class of .NET framework.

General usage

  • Creates a thread object and designates thread function as a parameter. The thread function is designated by constructor.
  • Creating a thread object does not mean immediate thread execution. Start must be run.
  • Either when calls Join or destructing the thread object, this waits until the running thread ends.

    You may create a routine that a thread will execute as Lambda Expression below.

CriticalSection critSec;
int totalWorkCount = 0;
volatile bool stopThread = false;
ThreadPtr th = ThreadPtr(new Thread([&]()
{
// note that thread function is defined exactly here
// and even the variables out of the scope are
// used here, thankfully by lambda capture above.
while (!stopThread)
{
CriticalSectionLock lock(critSec, true);
do_something();
totalWorkCount++;
}
});
th->Start();
do_something_or_wait();
stopThread = true;
th->Join();
print(totalWorkCount);

Constructor & Destructor Documentation

PROUD_API Proud::Thread::~Thread ( )

Destructor

  • Immediately returns if thread is not running but waits until the thread terminates if the thread is already running.

Member Function Documentation

Proud::Thread::__declspec ( property(get=GetHandle )

Thread handle

Proud::Thread::__declspec ( property(get=GetID )

Thread ID

HANDLE Proud::Thread::GetHandle ( )
inline

Gets thread handle

uint64_t Proud::Thread::GetID ( )
inline

Gets thread ID. This value is compatible to Proud.GetCurrentThreadID() value.

PROUD_API void Proud::Thread::Join ( )

Waits until the thread terminates

static PROUD_API void Proud::Thread::NotifyDllProcessDetached ( )
static

When ProudNet is used at DLL as a ststic library, this method must be called at Process detach case of DllMain.

PROUD_API void Proud::Thread::Start ( )

Creates thread

  • An exeption will ocur if already created.