Cross thread active objects
| Tue, 2007-10-09 08:51 | |
|
Hi, My application has two threads. One is the master (same as the helloworldbasic example in the s60 sdk) and the other that I explicitly create, is the slave. 1. Is there special ways of doing RThread::RequestComplete in case of cross thread communication? Please help. |
|






Forum posts: 11
Hi,
Problem is with calling RThread::RequestComplete(...) from another (slave) thread.
I imagine that you obtain Thread by calling RThread() function, and this function return current thread (Slave), what is right, not master thread as you assume. I have similar problem and solution is easy:
class CFoo : public CBase
{
// constructor must be called from master thread, because we need to obtain right Thread ID
CFoo()
{
iCurThread.Open( RThread().Id() );
};
~CFoo()
{
iCurThread.Close();
};
// can be called from any thread
void DoRequestComplet(...)
{
iCurThread.RequestComplet(...)
};
private:
RThread iCurThread;
};
I hope that, this you help. This work in my code very well.
Patrik
Forum posts: 159
Why do you need the threads, can't you just get rid of them and have a 'master' active object and a 'slave' active object?
Threads are only really needed when you need pre-emptive multitasking, do you need preemptive multitasking?
Forum posts: 5
Hi,
Vipako: This is true that RThread gives me the current thread handle only. I am storing a master thread handle (in a similar fashion) and use it whenever I need to signal the master thread.
Alert: The application has two threads because the slave is responsible for network send/recv (this is quite a huge application for streaming video over the internet) The slave thread receives AV data and decodes it not to mention rendering also is done by the slave thread. If I try doing all this in one thread my UI will become unresponsive (look like its hanged) whenever rendering or decoding would be in progress. (Rendering and decoding are expensive synchronous operations)
I forgot to mention one thing though, I get stray signal in my slave thread... The panic is given to it and it dies as soon as the panic happens. The UI (master) thread remains even after the panic. Does this mean that stray signal is being given to the slave thread? I installed a CActivescheduler in the slave thread and could schedule most of the AOs there. It seems really complicated as how can signalling the master thread cause stray signals in the slave thread.
Thoughts...
Forum posts: 159
"Alert: The application has two threads because the slave is responsible for network send/recv (this is quite a huge application for streaming video over the internet) The slave thread receives AV data and decodes it not to mention rendering also is done by the slave thread. If I try doing all this in one thread my UI will become unresponsive (look like its hanged) whenever rendering or decoding would be in progress. (Rendering and decoding are expensive synchronous operations)."
That's exactly what active objects are used for - to stop a UI from becomming unresponsive. You could have one active object to receive the data and another to render it. If either takes a long time that is still what active objects are for - you break a long running task such as rendering down into smaller steps with each smaller steps executed within a separate invocation of RunL().
However if you have implemented the rendering functionality yourself and it is synchronous then you can't do this unless you re-implement it, in which case threads may be easier, however if the rendering functions are Symbian functions then I cannot believe that they would have been implemented in a purely synchronous way.
Forum posts: 5
Hi,
1. I am using the CMMFCodec::ProcessL to decode data. It is standard API for decoding encoded data on Symbian. AFAIK standard decoders are all synchronous.
2. Even if I implement an asynchronous decoder, I don't think a single thread would be able to handle network (300 Kbps AV), Decoding, Rendering altogether. Please keep in mind that audio-video streaming operations are very time critical and I can't risk running some UI event RunL while I am painting the screen(or receiving data, or decoding data for rendering).
Forum posts: 131
Using second thread is the way to go if you want to achieve latency-free playback. Otherwise other active objects will interfere with your playback active object.
To answer the original question: I have had similar problems with inter-thread communication quite a while ago and the cause is the fact that RThread() really stores the handle of the current thread, that is, if you save the handle in the master thread and access it in the slave thread, you will get a handle of the slave thread which is indeed "current"! To get the desired behaviour, I had to get thread handle by iHandleToSave.Open(RThread().Id()).
Forum posts: 5
So rather than saving the handle I should save the ID and while using should create a RHandle to it.
Thanks for the reply... will try and let you guys know. However, one thing bothers me though, If RHandle (when accessed form slave thread) would actually be a handle to the slave thread (even if I created it in main thread) how could the RunL actually get trigerred in the main thread when I say RThread::RequestComplete from slave thread. (Pl. refer my original posting)
Forum posts: 1
Hi casual_kumar,
Did you managed to solve this problem
I got the same error and don`t know how to solve it.
Forum posts: 114
Hi,
Wouldn't it be better to use RMsgQueue to notify the events to other threads? The master thread posts the messages to the que and the slave thread keeps listening to the que.
Chao,
Raghav