class Core::Threads::Thread
Overview
#include <corethread.h> class Thread: public Core::Platform::IThreadEntry { public: // construction Thread(CStringPtr name = Platform::kThreadName); Thread(ThreadID threadId); // methods void start(); void terminate(); bool join(uint32 milliseconds); void setPriority(int priority); void setCPUAffinity(int cpu); int getPriority() const; ThreadID getID() const; CStringPtr getName() const; int getNativePriority() const; int64 getUserModeTime() const; int getErrors() const; Platform::Thread& getPlatformThread(); virtual int threadEntry() = 0; }; // direct descendants class WorkerThread; class ClientThread; class AtomicTestThread; class LockingThread; class SignalThread; class TestThread; class Thread; class ServerThread;
Inherited Members
public: // methods virtual int threadEntry() = 0;
Detailed Documentation
Thread class.
Construction
Thread(CStringPtr name = Platform::kThreadName)
Thread constructor.
The thread does not start executing
Parameters:
name |
Name of the thread |
Thread(ThreadID threadId)
Thread constructor with thread ID.
Opens an existing thread with a given ID.
Parameters:
threadId |
ID of an existing thread |
Methods
void start()
Start executing.
void terminate()
Terminate.
Might not be implemented for all platforms. Deprecated This function might be dangerous.
Attention
The thread might not exit cleanly and could leave the process in an inconsistent state.
bool join(uint32 milliseconds)
Wait for the thread to finish.
Depending on the platform implementation, the thread might be terminated after waiting for milliseconds.
Attention
Calling this function might block the execution for an unknown amount of time if the platform implementation ignores the parameter.
Attention
Calling this function might leave the process in an inconsistent state, see Thread::terminate.
Parameters:
milliseconds |
Time in milliseconds to wait before terminating the thread. |
Returns:
true if the thread finished execution, false if the thread was terminated after waiting for milliseconds or joining failed.
void setPriority(int priority)
Sets the priority of the thread.
Might not be implemented for all platforms.
Call this before calling Thread::start
Parameters:
name |
The priority of the thread |
See also:
Core::Threads::ThreadPriority
void setCPUAffinity(int cpu)
Sets the CPU affinity of the thread.
Might not be implemented for all platforms.
Call this before calling Thread::start.
Parameters:
name |
The CPU affinity of the thread |
int getPriority() const
Get the current priority of the thread.
Returns:
The current priority
See also:
Core::Threads::ThreadPriority
ThreadID getID() const
Get the ID of the thread.
Returns:
The thread ID
CStringPtr getName() const
Get the name of the thread.
Returns:
The thread name
int getNativePriority() const
Get the current priority of the thread represented in a platform-specific way.
Returns:
The current priority
int64 getUserModeTime() const
Get the time this thread has executed in used mode.
Attention
The exact time representation might be platform-specific
Returns:
The time this thread has executed in user mode
int getErrors() const
Report if anything went wrong.
Returns:
A combination of ThreadErrors, or 0 if none
Platform::Thread& getPlatformThread()
Get the platform-specific thread implementation object.
This object might reveal additional methods and attributes.
Returns:
The platform-specific thread implementation object