We talked about the use of multithreading in Symbian OS. This is a framework that is more frequently used in Symbian OS: Active Object (AO ).
Multithreading is widely used in traditional programs, but it is not necessarily a good choice for small devices with limited resources. Through the routine of the class, we can see that each thread needs to allocate a certain amount of memory. If all asynchronous operations are done through multithreading, it will be a great burden on the system. AO is designed to process asynchronous operations in the same thread.
AO works under the coordination of activescheduler (AS). When an AO sends an asynchronous request, the request function returns immediately. AO can continue to run or wait. After the asynchronous operation is complete, the as will be notified, and then it calls the runl function in the corresponding AO. Therefore, the common use of AO is to create a request function for asynchronous operations and then process the operation results in runl. For example, if we have a socket that needs to read some data from the network and then output the data, we need:
One request function:
Void MYA: requestreceive ()
{
Isocket. Recv (ibuf,..., istatus );
}
And runl:
Void MYA: runl ()
{
Iconsole-> printf (ibuf );
}
When using this Ao, You can first call requestreceive () and then continue to do other things. After the socket is read, as will call the runl of this Ao, then the accepted data will be printed. Of course, to actually use ao in a program, we still need to learn a lot. Now you only need to have a conceptual understanding of AO.
The following is an illustration in newlc, which basically outlines the active object framework: