ICurrentNonGUIThread

The ICurrentNonGUIThread class represents the current thread of execution. An object of this class contains information that the Open Class Library maintains for the current thread of execution. You are limited to a single object of this class.

This class provides functions that you can only apply to the current thread of execution. To obtain a reference to the object, use the static function INonGUIThread::current.

If the current thread of execution owns graphical user interface windows or processes events for such windows, use ICurrentThread instead of this class.


ICurrentNonGUIThread - Member Functions and Data by Group

Constructors & Destructor

Use these protected constructors to construct objects of this class.


[view class]
~ICurrentNonGUIThread
public:
virtual ~ICurrentNonGUIThread()
Destroys the object.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


[view class]
ICurrentNonGUIThread
public:
ICurrentNonGUIThread()
The constructor is protected to prevent the accidental creation of objects of this class. Creation of objects of this class is restricted to INonGUIThread::current.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


Current Thread Information

Use these members to access general information on the current thread.


[view class]
handle
public:
virtual IThreadHandle handle() const
Returns the thread handle for the current thread.

Return
The handle of the current thread.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes

OS/2 Considerations

The thread handle and thread ID are identical.

Windows Considerations

You must use the thread handle for the operating system thread and synchronization functions.


[view class]
id
public:
virtual IThreadId id() const
Obtains the current thread's identifier (thread id).

Return
The thread id of the current thread

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


Current Thread Support

Use these members to perform thread operations that only apply to the current thread.


[view class]
exit
public:
virtual void exit(unsigned long returnCode)
Ends the current thread with the specified return value.

returnCode
The code to return as the exit code for the thread.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


[view class]
remainingStack
public:
virtual unsigned long remainingStack() const
Obtains an approximation of the number of available bytes that remain on the stack. If the stack is not initialized, 0 is returned.

Return
The approximate number of bytes of stack remaining.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes

Windows Considerations

This function always returns 1000 because an approximation cannot be obtained.


[view class]
sleep
public:
virtual ICurrentNonGUIThread& sleep( unsigned long milliseconds )
Suspends the thread for a specified number of milliseconds.

milliSeconds
The number of milliseconds to sleep.

Return
A reference to the current thread

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes

AIX Considerations

The granularity for sleeping on AIX is in seconds. The number of milliseconds is divided by 1000 to determine the number of seconds the thread will sleep. If the number of milliseconds is less than 1 second, the thread will not sleep.


[view class]
waitFor
Allows the current thread to wait for a specified thread to end.


Overload 1
public:
virtual ICurrentNonGUIThread& waitFor( const INonGUIThread& anotherThread )
Waits for another thread without any timeout, i.e. it waits forever

anotherThread
The thread to wait for

Return
A reference to the current thread.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


Overload 2
public:
virtual ICurrentNonGUIThread& waitFor( const INonGUIThread& anotherThread, long timeout, bool* timedOut )
Waits for another thread, with a timeout that indicates how long (in milliseconds) how to wait before giving up. Also indicates via a boolean parameter whether the operation completed or timed out.

anotherThread
The thread to wait for

timeout The number of milliseconds to wait for the other thread to die.

timedOut Filled with true if the operation timed out, else false if the operation succeeded.

Return
A reference to the current thread.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


Overload 3
public:
virtual ICurrentNonGUIThread& waitFor( const INonGUIThread& anotherThread, long timeout )
Waits for another thread, with a timeout that indicates how long to wait (in milliseconds) before giving up.

anotherThread
The thread to wait for

timeout The number of milliseconds to wait for the other thread to die.

Return
A reference to the current thread.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


[view class]
waitForAllThreads
public:
virtual ICurrentNonGUIThread& waitForAllThreads( long timeout = - 1, bool* timedOut = 0 )
Allows the main thread to wait for all other threads that were started using INonGUIThread or IThread to end. This function may only be called from the main thread of the process.

timeout
-1 means wait indefinitely, 0 means do not wait, other positive values give the timeout period in milliseconds.
timedOut
An optional boolean value that is set to indicate whether the return was because of a timeout or a successful wait.

Return
A reference to the current thread.

Exception

IInvalidParameter is thrown if this function is called from a thread other than the main thread of the process.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


[view class]
waitForAnyThread
public:
virtual IThreadId waitForAnyThread(long timeout = - 1)
Allows the current thread to wait for the first termination to occur of any other threads in the current process. It accepts a timeout value, in milliseconds, that indicates how long to wait before giving up. The timeout defaults to -1, which means wait forever.

timeout
The number of milliseconds to wait for any other thread to die.

Return
The thread id of the thread that died.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


Starting and Stopping Threads

Use these methods to control the starting and stopping of threads.


[view class]
suspend
public:
virtual void suspend()
Suspends the current thread of execution.

If the current thread is supporting a graphical user interface (GUI), use ICurrentThread::suspend instead of this function.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


ICurrentNonGUIThread - Inherited Member Functions and Data

Inherited Public Functions

INonGUIThread

Inherited Public Data

Inherited Protected Functions

INonGUIThread
ICurrentNonGUIThread

Inherited Protected Data