<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://www.newlc.com" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>NewLC - How to perform context switching in symbian - Comments</title>
 <link>http://www.newlc.com/en/forum/how-perform-context-switching-symbian</link>
 <description>Comments for &quot;How to perform context switching in symbian&quot;</description>
 <language>en</language>
<item>
 <title>Re: How to perform context switching in symbian</title>
 <link>http://www.newlc.com/en/forum/how-perform-context-switching-symbian#comment-41685</link>
 <description>&lt;p&gt;Hello Priyanka,&lt;/p&gt;

&lt;p&gt;You can use the &quot;RMsgQueue&quot; templated class to send data and for call backs. There are asynchronous methods available in the RMsgQueue class.&lt;/p&gt;

&lt;p&gt;Client creates a global queue and waits for the notification for data/message availability on this queue&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;///Client side code somewhat looks like....&lt;br /&gt;RMsgQueue&amp;lt;TMyDataType&amp;gt; imsgQueue;&lt;br /&gt;iMsgQueue.CreateGlobal(KNullDesC, 128); // You can use create local if both the threads are in same process.&lt;br /&gt;iMsgQueue.NotifyDataAvailable(iStatus);&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;Server(thread2) opens the queue and sends notification/message/data on this queue whenever needed.&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;//Thread2 code looks something like....&lt;br /&gt;RMsgQueue&amp;lt;TMyDataType&amp;gt; iMsgQueue;&lt;br /&gt;iMsgQueue.Open(handle); //Handle sent to this thread from thread1&lt;br /&gt;....&lt;br /&gt;//When data available, notify the client&lt;br /&gt;TMyDataType data;&lt;br /&gt;//Initialize the variable &amp;quot;data&amp;quot;&lt;br /&gt;iMsgQueue.Send(data); //This will send the call back and/or data to the thread1and continues without blocking&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;In thread1 an AO should be implemented to handle the message notification. This guarantees that the T2 will continue its processing after call back and also the callback will run in T1&#039;s context.&lt;/p&gt;

&lt;p&gt;Hope this helps...&lt;/p&gt;

&lt;p&gt;Chao,&lt;br /&gt;
Ravi&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;</description>
 <pubDate>Fri, 21 Sep 2007 08:04:20 +0200</pubDate>
 <dc:creator>raghav_an</dc:creator>
 <guid isPermaLink="false">comment 41685 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: How to perform context switching in symbian</title>
 <link>http://www.newlc.com/en/forum/how-perform-context-switching-symbian#comment-40857</link>
 <description>&lt;p&gt;Even if the thread in question waits for certain time and allows other threads to do their own business, it still continues (in it&#039;s turn) to execute the function it should not be executing, am I right? I cannot see how simpy waiting for a bit can make other thread to start executing a function.&lt;/p&gt;

&lt;p&gt;I have this kind of problem because i have to use a component which is apparently not thread safe.&lt;/p&gt;

&lt;p&gt;So I think my solution would be to send some kind of message to my application&#039;s message handling to handle completion event in it&#039;s own thread.&lt;/p&gt;</description>
 <pubDate>Tue, 21 Aug 2007 12:25:34 +0200</pubDate>
 <dc:creator>anttikarhu1</dc:creator>
 <guid isPermaLink="false">comment 40857 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: How to perform context switching in symbian</title>
 <link>http://www.newlc.com/en/forum/how-perform-context-switching-symbian#comment-40854</link>
 <description>&lt;p&gt;&lt;div class=&quot;bb-quote&quot;&gt;&lt;blockquote class=&quot;bb-quote-body&quot;&gt;It just suspends the current thread for certain amount of time&lt;/blockquote&gt;&lt;/div&gt; .. giving the scheduler a chance to run other threads that could run. Have you tried this? It doesn&#039;t work for you?&lt;/p&gt;

&lt;p&gt;You can also take a look at RThread::Open and RThread::Resume (to find and run the other thread) and RThread::Suspend to suspend a thread.&lt;/p&gt;</description>
 <pubDate>Tue, 21 Aug 2007 09:27:48 +0200</pubDate>
 <dc:creator>Andreas</dc:creator>
 <guid isPermaLink="false">comment 40854 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: How to perform context switching in symbian</title>
 <link>http://www.newlc.com/en/forum/how-perform-context-switching-symbian#comment-40847</link>
 <description>&lt;p&gt;&quot;Try adding User::After(100) or a similar small value in the AO, before it starts processing the callback result. This should enable the system to switch to the other thread, since this thread is now idle for a small amount of time and the turn can be given to others.&quot;&lt;/p&gt;

&lt;p&gt;Does that change thread context? I don&#039;t think so. It just suspends the current thread for certain amount of time, and the callback will still be called and executed in thread B.&lt;/p&gt;

&lt;p&gt;Anyone has a solution for this? I have a same problem too. I&#039;m quite new to Symbian OS. In .NET programming, there was a Invoke-method, which was used to change the thread context. It relies on the window handle, and i believe it raises some soft of event which is handled in the target thread to change context.&lt;/p&gt;</description>
 <pubDate>Mon, 20 Aug 2007 15:47:20 +0200</pubDate>
 <dc:creator>anttikarhu1</dc:creator>
 <guid isPermaLink="false">comment 40847 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: How to perform context switching in symbian</title>
 <link>http://www.newlc.com/en/forum/how-perform-context-switching-symbian#comment-39483</link>
 <description>&lt;p&gt;Try adding User::After(100) or a similar small value in the AO, before it starts processing the callback result. This should enable the system to switch to the other thread, since this thread is now idle for a small amount of time and the turn can be given to others.&lt;/p&gt;</description>
 <pubDate>Mon, 25 Jun 2007 09:41:14 +0200</pubDate>
 <dc:creator>Andreas</dc:creator>
 <guid isPermaLink="false">comment 39483 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: How to perform context switching in symbian</title>
 <link>http://www.newlc.com/en/forum/how-perform-context-switching-symbian#comment-39473</link>
 <description>&lt;p&gt;Thanks for ur reply.&lt;/p&gt;

&lt;p&gt;But this will not solve my problem because after creating AO the callback still run in caller context.&lt;br /&gt;
Actually i want to switch thread.....is there any way to switch between threads???&lt;/p&gt;

&lt;p&gt;Problem Description:&lt;/p&gt;

&lt;p&gt;There are two modules A and B. Module A will send buffer data for decoding to module B which in turn send this buffer to decoder...after sending data to decoder module B send notification to module A via callback. Now module A and module B both running in different threads. Also when data is decoded module B will send decoded data to module A in the callback and should return from this call within 5 msec. Then module A will send the decoded data to the sink.&lt;/p&gt;

&lt;p&gt;Problem is when module B send data to module A in the callback it is called in module B&#039;s thread. I want to switch to thread A and return from the callback. And then performed rest of the operation in thread A context.&lt;/p&gt;

&lt;p&gt;Hope i explained my doubt clearly.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;</description>
 <pubDate>Mon, 25 Jun 2007 06:58:34 +0200</pubDate>
 <dc:creator>PriyankaP</dc:creator>
 <guid isPermaLink="false">comment 39473 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: How to perform context switching in symbian</title>
 <link>http://www.newlc.com/en/forum/how-perform-context-switching-symbian#comment-39386</link>
 <description>&lt;p&gt;You control the CIdle with what you return from your callback.&lt;/p&gt;

&lt;p&gt;Just return EFalse on the first call and it will not be rescheduled.&lt;/p&gt;

&lt;p&gt;No need to destroy the CIdle, if you don&#039;t want to destroy it for resource saveing. (It only takes a few bytes memory though)&lt;/p&gt;

&lt;p&gt;But could be nice to keep it there for the next time it is needed, to not need OOM-handling in the event callback.&lt;/p&gt;

&lt;p&gt;I don&#039;t see any reason to re-implement it, your own active object would look and work pretty much identical.&lt;br /&gt;
&lt;/p&gt;</description>
 <pubDate>Thu, 21 Jun 2007 14:12:38 +0200</pubDate>
 <dc:creator>alh</dc:creator>
 <guid isPermaLink="false">comment 39386 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: How to perform context switching in symbian</title>
 <link>http://www.newlc.com/en/forum/how-perform-context-switching-symbian#comment-39385</link>
 <description>&lt;p&gt;True, you could use CIdle. Note, though, that CIdle gets the chance to run every time no other thread (application) or AO is run, so effectively it is active is nothing else is active -- all the time. Consuming the power of the device. So if you use CIdle, remember to destroy it as long as you&#039;ve done with it. Or create your own as described, that is not activated until necessary (you get the callback called) and is active only if the callback was actually called.&lt;/p&gt;</description>
 <pubDate>Thu, 21 Jun 2007 13:43:45 +0200</pubDate>
 <dc:creator>Andreas</dc:creator>
 <guid isPermaLink="false">comment 39385 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: How to perform context switching in symbian</title>
 <link>http://www.newlc.com/en/forum/how-perform-context-switching-symbian#comment-39383</link>
 <description>&lt;p&gt;CIdle is a nice and easy-to-use active object derived class that implements an AO that behaves like Andreas describe.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;</description>
 <pubDate>Thu, 21 Jun 2007 13:37:02 +0200</pubDate>
 <dc:creator>alh</dc:creator>
 <guid isPermaLink="false">comment 39383 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: How to perform context switching in symbian</title>
 <link>http://www.newlc.com/en/forum/how-perform-context-switching-symbian#comment-39382</link>
 <description>&lt;p&gt;Create an active object that is activated as the callback is called. The AO doesn&#039;t start processing the callback immediately, so the control returns to the caller. Then when the AO is run, it can handle the callback.&lt;/p&gt;

&lt;p&gt;The AO is implemented so that it does not use any resource (R-class) but itself completes the request, as it gets the turn from the scheduler. There are examples of this on this forum and elsewhere.&lt;/p&gt;</description>
 <pubDate>Thu, 21 Jun 2007 12:42:28 +0200</pubDate>
 <dc:creator>Andreas</dc:creator>
 <guid isPermaLink="false">comment 39382 at http://www.newlc.com</guid>
</item>
<item>
 <title>How to perform context switching in symbian</title>
 <link>http://www.newlc.com/en/forum/how-perform-context-switching-symbian</link>
 <description>&lt;p&gt;--------------------------------------------------------------------------------&lt;/p&gt;

&lt;p&gt;Hi all,&lt;/p&gt;

&lt;p&gt;I have a callback function, which is called by lower layer via function pointer to notify the application when an event of interest occurs.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;http://www.newlc.com/en/forum/how-perform-context-switching-symbian&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://www.newlc.com/en/forum/how-perform-context-switching-symbian#comments</comments>
 <category domain="http://www.newlc.com/en/forums/audio">Audio</category>
 <pubDate>Thu, 21 Jun 2007 09:00:03 +0200</pubDate>
 <dc:creator>PriyankaP</dc:creator>
 <guid isPermaLink="false">18159 at http://www.newlc.com</guid>
</item>
</channel>
</rss>
