Symbian multi-thread programming

Source: Internet
Author: User

As an OS, Symbian also provides traditional inter-thread communication. For more information, see rsemaphore, rmutex, rchunk (shared memory), and Message Queue rmsgqueuebase provided in version 3.

Note: the C/S mode is based on rsemaphore. Therefore, when the client calls sendrecieve (), the client waits for the server (rsemaphore. wait (), after receiving by the server (rsemaphore. signal () will notify the client, and then the client will continue to execute.

If it is only a simple signal, you can use rthread: requestcomplete to send a completion event to the other party.

Function onclick ()
Tagshow (Event)
} "> 2.
Function onclick ()
Tagshow (Event)
} "> Thread {
Function onclick ()
Tagshow (Event)
} "> The object classes include rthread, dthread, and nthread.
Rthread is {
Function onclick ()
Tagshow (Event)
} "> At the user layer, dthread is at the kernel layer and nthread is at the nanokernel layer.
User layer {
Function onclick ()
Tagshow (Event)
} "> The Code creates a thread with rthread, the kernel and the driver need to create a thread with dthread, And the nano kernel layer creates a thread with nthread.
A rthread has a dthread, and a dthread has a nthread.
Rthread is like the dthread encapsulation and handle, which can be used by users.
The user layer needs to create a thread, rthread: create will be called, it will pass {
Function onclick ()
Tagshow (Event)
} "> System interface call dthread: create,
Dthread: Create will replace dthread: docreate, and dthread: docreate will call nkern: threadcreate to create the nanokernel part of the thread.
Therefore, when you create an rthread, A dthread is generated, and a dthread is generated.
The dthread class has a member nthread inthread;
This member is the nthread associated with it.
A rthread has a dthread, which is easy to understand. Why does a dthread have a nthread,
This is mainly because the final scheduling object in Symbian is nthread.

1) multithreading has higher runtime requirements than activity objects. For example, context switching between threads is an order of magnitude slower than switching of activity objects in the same thread; threads require greater space overhead, generally, threads need 4 K kernel space and 8 K user space for the program stack; in contrast, the active object only needs to occupy the space of the C ++ object (usually less than 1 K ).
2) The biggest difference between using a thread and using an active object to implement multi-task is that the former is preemptible by the kernel, and the latter's collaborative multi-task occurs in one thread, and once an event is processed, the activity object cannot be preemptible by its active scheduler (So runl must return quickly; otherwise, it will block the main thread, that is, the event processing should be as short as possible ).
However, multithreading is still required in many cases, as shown below:
A. Multimedia Processing
B. Porting procedures
C. A task cannot be divided into short fragments.
D. To ensure the continuity of the executed task, such as playing sound
In this way, the thread can be implemented in the newly created thread, so that the thread can be run asynchronously without affecting the response of the application to user interface events.
PS: the access interface (drawing screen, etc.) under Symbian must be in the main thread
3) To protect the thread from Potential Malicious Code troubles, a thread is not allowed to manipulate other threads after Symbian 8.0 (this is also the execution of receivethread in the main thread. kill (0) causes the program to exit ).
4) You can specify the minimum and maximum heap size as the main thread of the components running the separation process in the. MMP file.
Epocheapsize minsize maxsize
5) when writing multi-threaded code, the thread should not be given a high priority. Otherwise, it may seize other threads in the system.
6) The default priority of all threads is eprioritynormal. When a thread is created, it is set to suspended and will not start running until resume () is called ()
7) Data pointers cannot be directly transmitted between threads because the process address space is protected and isolated from each other.
8) Each thread has its own heap and stack. The main program has a default cleanstack, and the newly created thread must be manually created to clear the stack.
9) Multiple Threads can access resources by synchronizing objects (rsemaphore, rmutex, rchunk. By limiting or directly locking resources, we can ensure that only one thread can write operations on resources at a time point, such as the critical section)

Thread priority (relative to the priority of the process)
-Eprioritynull (-30)
-Eprioritymuchless (-20)
-Epriorityless (-10)
-Eprioritynormal (0)
-Eprioritymore (+ 10)
-Eprioritymuchmore (+ 20)
-Epriorityrealtime (+ 30)

Terminate thread
-You can use rthread: Kill (tint areason) to terminate a thread.
-Rthread provides exittype () and exitreason () to return the reason for thread termination.
-Exittype () returned values include
· Eexitkill: Call the kill () function when the thread function returns or displays the result.
· Eexutpanic: the thread ends due to a serious error.
· Eexitpending: The thread is still running.
-Exitreason () returned values include
· Return code: the thread function returns normally.
· Final code: the thread calls the kill () function.
· Error code: the thread exits due to a serious error.
· Zero: The thread is still running

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.