.From Forum Nokia WikiIn Symbian,
the class RThread is used to manipulate threads. An object of type RThread represents a handle to a thread, because the thread itself is a kernel object. An RThread object can be used to create or refer to another thread in order to manipulate it.
The base class of RThread is RHandleBase, which encapsulates the behavior of a generic handle and is used as a base class throughout Symbian OS to identify a handle to another object, often a kernel object.
RThread, RProcess, RMutex and RSession-Base are derived from RHandleBase.
Contents [hide]
1 Creating a Thread
2 Stopping a Running Thread
3 Killing a Running Thread
4 Getting the exit reason of a Thread
5 Getting Notification of Thread End.
Creating a Thread
/* Name of the new thread */
_LIT(KThreadName, "MyFirstThread");
/* Creates a thread belonging to the current process and opens this handle to that thread. */
TInt res = iThread.Create(KThreadName, ThreadEntryPoint, KDefaultStackSize, NULL, &iVariable);
/* Makes the thread eligible for execution.After a thread is created, it is put into a suspended state; the thread is not eligible to run until Resume() is called. */
iThread.Resume();
/* Control passes to this function when the thread is first resumed, i.e. when the thread is initially scheduled to run. This function just changes the value of the variable. */
TInt CThreadExampleAppUi::ThreadEntryPoint(TAny* param)
{
TInt* para = static_cast<TInt *>(param);
*para = 1;
return 1;
}
Stopping a Running Thread A running thread can be removed from the scheduler’s ready-to-run queue by a call to Suspend() on its thread handle. It still exists, however, and can be scheduled to run again by a call to Resume().
Killing a Running Thread A thread can be ended permanently by a call to Kill() or Terminate(), both of which take an integer parameter representing the exit reason. You should call Kill() or Terminate() to stop a thread normally, reserving Panic() for stopping the thread to highlight a programming error. If the main thread in a process is ended by any of these methods, the process terminates too.
Getting the exit reason of a Thread The manner by which the thread was stopped, and its exit reason, can be determined from the RThread handle of an expired thread by calling ExitType(), ExitReason() and ExitCategory(). The exit type indicates whether Kill(), Terminate() or Panic() was called or, indeed, if the thread is still running. The exit reason is the integer parameter value passed to the Kill() or Terminate() functions, or the panic reason. The category is a descriptor containing the panic category, Kill or Terminate. If the thread is still running, the exit reason is zero and the exit category is a blank string.
Getting Notification of Thread End. It is also possible to receive notification when a thread dies. A call to RThread::Logon() on a valid thread handle, passing in a TRequest- Status reference, submits a request for notification when that thread terminates.
The request completes when the thread terminates and receives the value with which the thread ended or KErrCancel if the notification request was cancelled by a call to RThread::LogonCancel().