close

1.Shared Memory

A crude and straightforward way to exchange information between threads is to use shared memory.

Thread entry point function takes one parameter, TAny *aPtr. This pointer can be used for any purpose. Often it is used to pass a pointer to a data structure or class instance that contains the information shared between threads. Because threads within a same process share the same memory address space, the data pointed to by that pointer can be used normally after casting it to the proper type, except that access to this data must be synchronized.

In Symbian OS 7.0s and earlier versions, the pointer given to the thread function can be changed afterwards by calling SetInitialParameter(TAny* aPtr) on the suspended thread. Platform security changes removed this function, so in the OS versions 7.0s onwards, the thread has to be created with function TInt RThread::Create(const TDesC &aName, TThreadFunction aFunction, TInt aStackSize, RAllocator *aHeap, TAny *aPtr, TOwnerType aType=EOwnerProcess). If aHeap is NULL, then the new thread uses the heap of the creating thread. If heap is not shared by giving it as a parameter, USER 42 panic may appear when trying to use the memory of another thread's heap.

Sharing the heap does not mean that the R-class sessions are shared between threads. This can be achieved, for example in the case of RFs, by calling the function RSessionBase::ShareAuto().

2.Client/Server API

A client makes use of services provided by a server. The server receives request messages from its clients and handles them, either synchronously or asynchronously. Data is passed from the client to the server in the request message itself or by passing a pointer to a descriptor in the client address space, which the server accesses using kernel-mediated data transfer. On Symbian OS, servers are typically used to manage shared access to system resources and services. The use of a server is efficient since it can service multiple client sessions and can be accessed concurrently by clients running in separate threads.

Symbian OS offers a server/session based API that enables one thread to act as a server and to provide services for other threads and processes. This API also offers a convenient way to handle message passing, synchronization, and data transfer.

Related: Client-Server Framework

Inter-Process Data Transfer

Inter-Process Data Transfer

 

 

3.Thread-Local Storage (TLS)

On EKA1, Symbian OS doesn’t allow Writeable Static Data (WSD for short) in DLLs. There is, though, one 32-bit word allocated per thread per DLL. This word can be used as a pointer to the data structure or class instance. The allocation and de-allocation of this structure can be done, for example, in a DLL entry point function E32Dll.

The TLS slot can be used directly if you have only one machine word of data to store. For extensibility, it is more likely that you’ll use it to storea pointer to a struct or simple T Class which encapsulates all the data you would otherwise have declared as static.

Thread-local storage is usually initialized when the DLL is attached to a thread within the DLL entry point, E32Dll().

The Dll::SetTls(TAny *aPtr) function sets the pointer to thread-local storage. The Dll::Tls() function returns a pointer to thread-local storage. The data pointed to by that pointer can be used normally.

On EKA2, WSD can be used see Writeable Static Data for more details.

4.Exception Handling

In Symbian OS, there are lots of events that can raise exceptions on other threads. These exceptions are not equivalent to ANSI C++ exceptions.

On EKA1, the RThread API supports thread exception management. On the more secure EKA2 platform, this has moved into class User and applies only to the current thread.

The following functions are involved in exception handling:

 

RThread::ExceptionHandler()
RThread::SetExceptionHandler()
RThread::ModifyExceptionMask()
RThread::RaiseException()
RThread::IsExceptionHandled()

 

TInt SetExceptionHandler(TExceptionHandler* aHandler, TUint32 aMask);

SetExceptionHandler() allows you to define an exception handler function for the thread for which the handle is valid.

 

5.Publish & Subscribe

Publish & Subscribe is an inter-process communication mechanism introduced in Symbian OS v8.0a.

This mechanism includes three basic entities: properties,publishers and subscribers.

Properties are single global variables that are identified by a standard Symbian OS UID that defines the property category, and another integer that defines the property sub-key.

Publishers are threads that update a property.

Subscribers are threads that listen to changes to a property.

 

6.Message Queues

Message queues are used to send messages to queue without knowing the identity or existence of the recipient. Any process (in the case of global queues) or any thread within the same process (in the case of local queues) may read these messages.

For more information, refer to Message Queues

 

arrow
arrow
    全站熱搜

    NatPixnet 發表在 痞客邦 留言(0) 人氣()