System::Threading::Thread class
Contents
[
Hide
]Thread class
Thread implementation. Objects of this class should only be allocated using System::MakeObject() function. Never create instance of this type on stack or using operator new, as it will result in runtime errors and/or assertion faults. Always wrap this class into System::SmartPtr pointer and use this pointer to pass it to functions as argument.
class Thread : public System::Object
Methods
Method | Description |
---|---|
Abort() | Aborts thread. Not implemented. |
get_CurrentCulture() | Gets thread culture. |
static get_CurrentThread() | Gets object which describes current thread. |
get_CurrentUICulture() | Gets user interface culture used by thread. |
get_IsAlive() | Checks whether thread is alive. |
get_IsBackground() | Checks whether thread is background. |
get_IsThreadPoolThread() | Checks if thread is owned by a thread pool. |
get_ManagedThreadId() const | Gets identifier of thread. Can be got from OS, but if OS thread identifier exceeds int limits, ids of threads can intersect. |
get_Name() | Gets thread name. |
get_ThreadState() | Gets thread state. |
static GetCurrentThreadId() | Gets identifier of current thread. |
GetHashCode() const override | |
Interrupt() | Interrupt thread. Not implemented. |
Join() | Joins managed thread. Performs unlimited waiting if required. |
Join(int) | Joins managed thread. Performs limited waiting. |
Join(TimeSpan) | Joins managed thread. Performs limited waiting. |
static MemoryBarrier() | Synchronizes memory access. |
operator=(const Thread&) | Copies TLS data from different thread. |
set_CurrentCulture(const SharedPtr<Globalization::CultureInfo>&) | Sets thread culture. |
set_CurrentUICulture(const SharedPtr<Globalization::CultureInfo>&) | Sets user interface culture used by thread. |
set_IsBackground(bool) | Sets thread to background or foreground. |
set_Name(const System::String&) | Sets thread name. |
static Sleep(int) | Stops current thread for specified timeout. |
static Sleep(TimeSpan) | Stops current thread for specified timeout. |
static SpinWait(int) | Waits for specific number of loop iterations. |
Start() | Starts thread using null argument object. |
Start(const System::SharedPtr<System::Object>&) | Starts thread. |
Thread() | Constructor. |
Thread(ThreadStart) | Constructor. |
Thread(ParameterizedThreadStart) | Constructor. |
Thread(Thread&) | Copy constructor. |
static Yield() | Yields thread. |
virtual ~Thread() | Destructor. |
Remarks
#include "system/threading/thread.h"
#include "system/smart_ptr.h"
int main()
{
auto thread = System::MakeObject<System::Threading::Thread>([]()
{
std::cout << "Child thread ID: " << System::Threading::Thread::GetCurrentThreadId() << std::endl;
System::Threading::Thread::Sleep(200);
});
std::cout << "Main thread ID: " << System::Threading::Thread::GetCurrentThreadId() << std::endl;
thread->Start();
thread->Join();
return 0;
}
/*
This code example produces the following output:
Main thread ID: 2
Child thread ID: 1
*/
See Also
- Class Object
- Namespace System::Threading
- Library Aspose.TeX for C++