×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    5

    Accessing objects from another Thread

    Hello!

    I'm very new to Symbian C++ and I've got a problem which is probably quite easy to solve.

    I have written a very basic console-application. I'm starting a thread from within that application which starts an CActive object itself. To get a little bit of control over the new thread, I tried the CAsyncCallBack-class (following this Post). When I create the CAsyncCallBack within the new thread every call to this object from another thread (main-thread in this case) results in a Main Panic KERN-EXEC 3.

    I think this behaviour is very basic and is not only bound to CAsyncCallBack-objects but to any object which is created in a different thread than the caller thread. There has to be a very substantial problem of understanding on my side. In my opinion I followed the above mentioned post exactly .

    The testcase doesn't use classes or special CActives, but breaks anyway at the same place (
    Code:
    (*capturer).Call();
    ).

    Edit: Obviously placing the (*capturer).Call() just under the iThread.Create-line is a bad idea, because the thread might not be started immediately. So the pointer points to nothing. However the problem remains, that even if I use a user-triggered CActive for executing the CAsyncCallBack.Call the same error occurs.

    Note: When I used a CActive within the main-thread the Debugger told me that the adresses in both threads were identical. However I wasn't allowed to execute anything.

    I hope you can help me.
    Thanks
    Klemens

    Code:
    LOCAL_D TInt CallBack(TAny*)
    {
    	// do something
    }
    
    TInt ThreadEntryPoint(TAny* param)
    {
    	CTrapCleanup* cleanup = CTrapCleanup::New();
    	
    	TRAPD(mainError, doL(param));
    }
    
    
    void doL(TAny* param) {
    
    	CActiveScheduler* exampleScheduler = new (ELeave) CActiveScheduler;
    
    	// Push onto the cleanup stack
    	CleanupStack::PushL(exampleScheduler);
    
    	// Install as the active scheduler
    	CActiveScheduler::Install(exampleScheduler);
    	
    	CAsyncCallBack* cb = new CAsyncCallBack(CActive::EPriorityStandard);// = new (ELeave) CGlobalCapturer()
    	cb->Set(TCallBack(CallBack,NULL));
    	
    	(*(CAsyncCallBack**) param) = cb;
    	
    	CActiveScheduler::Start();
    	
    	CleanupStack::PopAndDestroy( exampleScheduler );
    } 
    
    LOCAL_C void mainL()
    {
    	// Construct and install the active scheduler
    	CActiveScheduler* exampleScheduler = new (ELeave) CActiveScheduler;
    
    	// Push onto the cleanup stack
    	CleanupStack::PushL(exampleScheduler);
    
    	// Install as the active scheduler
    	CActiveScheduler::Install(exampleScheduler);
    	
    	console->Write( _L( "Starting key capturing\n" ) );
    	
    	RThread iThread;
    	CAsyncCallBack* capturer;
    	
    	TInt res = iThread.Create(KThreadName, ThreadEntryPoint, KDefaultStackSize, NULL, &capturer);
    	iThread.Resume();
    	
    	(*capturer).Call();
    	
    	// Main part of program is a wait loop
    	// This function completes when the scheduler stops
    	CActiveScheduler::Start();
    	
    	console->Printf(_L("Draussen!"));
    
    	// Remove from the cleanup stack and destroy:
    	// 1. exampleScheduler
    	CleanupStack::PopAndDestroy(1);
    }
    Last edited by Saxer; 2008-08-24 at 16:26.

  2. #2
    Registered User
    Join Date
    Jun 2008
    Posts
    5

    Re: Accessing objects from another Thread

    Problem solved! My pointer-pointer wasn't initialized.

Similar Threads

  1. S60 SDK 3rd edition FP1 Emulator problem
    By justteam in forum Symbian Tools & SDKs
    Replies: 14
    Last Post: 2010-03-23, 08:47
  2. console app running problem
    By xcompass in forum Symbian C++
    Replies: 3
    Last Post: 2009-05-08, 13:26
  3. 为什么会启动这么多的线程
    By shaojieli in forum Symbian
    Replies: 1
    Last Post: 2008-08-19, 05:34
  4. Carbide C++ : ..... .pkg does not exist. Skipping...
    By satishkatta in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 144
    Last Post: 2008-08-07, 11:16
  5. Link errors when trying to Display bitmap
    By Bkc82 in forum Symbian Media (Closed)
    Replies: 1
    Last Post: 2006-01-16, 22:46

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •