## class XGThread

> Declared in <XThread.h>

> This is the thread object; this knows how to handle, identify, fold, and mutulate a thread object.

> Attach/Detach semantics provides me a way to manipulate a thread, even after the thread dies. Normally, the XGThread class pointer is owned by the thread--when the thread dies, the XGThread class object is deleted. This sucks if you want to keep a pointer to the thread object pass it's expiration.

> Thus, the Attach/Detach semantics allows other objects to keep a pointer to the XGThread, and claim ownership past the thread's termination.

> Note that when the thread is first created, it's owned by the thread itself. That means if you want to create this thread and keep a pointer to that thread, you need to explicitly attach to the thread after it's creation: thus,

> XGThread ptr = new XGThread(myProc,0,0,true); // create suspended ptr->Attach(); // attach to it ptr->Resume(); // and resume execution

Construction/Destruction

> XGThread::XGThread
> XGThread::XGThread
> XGThread::~XGThread

Attach/Detach

> XGThread::Attach
> XGThread::Detach
> XGThread::GetAttach

Thread Management

> XGThread::CurrentThread
> XGThread::GetThreadCount
> XGThread::IsAlive
> XGThread::IsSuspend
> XGThread::Kill
> XGThread::Resume
> XGThread::SetThreadPool
> XGThread::Suspend
> XGThread::YieldThread

Construction/Destruction

XGThread::XGThread

> Usage: XGThread::XGThread(XGThreadProcPtr proc,long arg,long stack,bool suspend)

> Create this thread. Calls the procudure specified inside the thread. The 'arg' field gives the four-byte argument which is used to invoke the provided procedure. The 'stack' object gives the size of the stack; if zero, the stack is set to the default size. And 'suspend', if true, creates this thread in the suspended state.

XGThread::XGThread

> Usage: XGThread::XGThread()

> This is a special constructor, which should never be called by another procedure, which creates the thread which represents the main task.

XGThread::~XGThread

> Usage: XGThread::~XGThread()

> Stop this thing if it's running

Attach/Detach

XGThread::Attach

> Usage: void Attach(void)

> Increments the attach count. When created, this thread has an attach count of 1, corrisponding to the thread procedure which owns this thread.

XGThread::Detach

> Usage: void Detach(void)

> Decrements the attach count, and if the count reaches zero, deletes this object.

XGThread::GetAttach

> Usage: long GetAttach(void)const

> Returns the attach count for this object

Thread Management

XGThread::CurrentThread

> Usage: XGThread*XGThread::CurrentThread()

> Which is the current thread object? Get the thread ID and search for the current thread object

XGThread::GetThreadCount

> Usage: static long GetThreadCount()

> Returns the number of threads that currently exist

XGThread::IsAlive

> Usage: bool XGThread::IsAlive(void)

> Is this thread alive?

XGThread::IsSuspend

> Usage: bool XGThread::IsSuspend(void)

> Is this thread suspended?

XGThread::Kill

> Usage: void XGThread::Kill(void)

> Kill this thread

XGThread::Resume

> Usage: void XGThread::Resume(void)

> Resume specified thread

XGThread::SetThreadPool

> Usage: void XGThread::SetThreadPool(short pool,long stack)

> Macintosh specific; calls the 'CreateThreadPool' routine in the thread manager

XGThread::Suspend

> Usage: void XGThread::Suspend(void)

> Suspend the specified thread

XGThread::YieldThread

> Usage: void XGThread::YieldThread(bool f)

> Yield to any thread (If no thread support, return immediately)

> 'true' if I should yield the rest of my processor timeslice