|
|
User login
Feeds |
How to share CFbsBitmap instances between threads?
|
|||||
| Mon, 2005-08-01 14:52 | |
|
Hi Experts,
I have a problem sharing CFbsBitmap objects between threads. Symabian's SDK document says to use "Duplicate()" function of CFbsBitmap class for this. But i am unable to do it. I tried using Duplicate in two ways but it does not help. Below is the code. 1.   MAIN THREAD:     iImage=(CFbsBitmap*)new CFbsBitmap; //iImage is a member variable of CExampleAppUi     TInt Err = iImage->Create(cif_size,EColor64K);     if(Err != KErrNone)    {     RDebug::Printf("\nUnable to allocate mem for image--Error = %d", Err);     }    Create a new thred here and pass "this" pointer. "this" pointer is pointing to CExampleAppUi object   CHILD THREAD:    CFbsBitmap* Image = STATIC_CAST(CExampleAppUi*,param)->iImage; //param is parameter received by the static thread func.    CFbsBitmap* iBitmap = new (ELeave) CFbsBitmap();    TInt temp = Image->Handle();    RDebug::Printf("Got the handle %d", temp); //Getting the handle correctly    temp = iBitmap->Duplicate(temp);   RDebug::Printf("Duplicated the handle with the return value %d", temp);  Duplicate returns with the value -34, which ,means "KErrCouldNotConnect" . So i am not able to duplicate the handle this way. 2.   MAIN THREAD     iImage=(CFbsBitmap*)new CFbsBitmap; //iImage is a member variable of CExampleAppUi     TInt Err = iImage->Create(cif_size,EColor64K);     if(Err != KErrNone)    {     RDebug::Printf("\nUnable to allocate mem for image--Error = %d", Err);     }    iDuplicateImage = new (ELeave) CFbsBitmap();  // iDuplicateImage is member variable of CExampleAppUi    TInt temp = iImage->Handle();    RDebug::Printf("Got the handle %d", temp);     // getting the handle correctly    temp = iDuplicateImage->Duplicate(temp);   RDebug::Printf("Duplicated the handle with the return value %d", temp);  //Duplicate returns 0 means success in duplicating    Create a new thred here and pass "this" pointer. "this" pointer is pointing to CExampleAppUi object   CHILD THREAD:    CFbsBitmap* Image = STATIC_CAST(CExampleAppUi*,param)->iDuplicateImage; //param is same as above    Image->LockHeap(ETrue);    Now it gives me KERN-EXEC 0 error. I am unable to solve this issue. What might be the reason? Am i doing any mistake?? Please help me in this regards, Thanks Pinky   |
|
Forum posts: 142
General rule with symbian OS is that Handles are thread specific, so you can not share them between threads. anyway I also remember reading about bitmaps, that the memory area for them is implemented in global chunk, this is for the drawing access, didn't really read it too well so can not remember details. Anyway, if it is really implemented as such, then there should be ways to access this data from other processes as well.
Anyway, in case you are running both of the threads in same process, you could share pointers, so maybe you could workaround using the pointer to the data area of the bitmap image.
Have to say that I haven't really done too much threads programming, so can be considered a rookie on this issue.
yucca
Forum posts: 173
Image->LockHeap(ETrue);
If it is the case, then it means
Image is pointing to Null. In other words
iDuplicateImage is not the one from Main thread.
http://sandy.t35.com
Forum posts: 35
IN MAIN THREAD:
RDebug::Printf("Duplicated image %x", iDuplicateImage);
RDebug::Printf("DataAddress for Original image %x", iImage->DataAddress());
RDebug::Printf("DataAddress for Duplicated image %x", iDuplicateImage->DataAddress());
// First Print gives non-zero, meaning that iDuplicateImage is a valid object. The second and 3rd prints both give the same address,meaning that both are pointing to same address which had been allocated for iImage in main thread.
IN CHILD THREAD:
RDebug::Printf("Image in thread %x", Image);
This print in the child thread prints the same value as the first print is printing in the main thread. So It is same as iDuplicateImage. I can not print the address pointed by this because for that i will have to LockHeap first, which is panicing.
Thx
Pinky
Image->LockHeap(ETrue);
If it is the case, then it means
Image is pointing to Null. In other words
iDuplicateImage is not the one from Main thread.
Forum posts: 142
yucca
Forum posts: 35
I have already tried the Image->Handle(). Its same as in the main thread. So its not a problem with the handle.
Thx
Pinky
Forum posts: 142
yucca
Forum posts: 35
Pinky
Forum posts: 1
I am also facing the same issue. i.e After duplicating the CFbsBitmap, LockHeap() is panicking with KERN-EXEC 0.
Handle numbers are same for both pointers of CFbsBitmap before and after Duplicating it.
Please help me in this regard.
Thanks
nsat
Forum posts: 1271
The whole point of them is to share them between threads (or even processes).
I don't know where you got the information that handles are usually thread specific.
The main reason for handles to exist in any os is otherwise because you want to share them between threads and processes. You have a handle because you can't share pointers, and you ask the system for access to the handle, which then gives you this and a pointer into the process own adress space where it can be found.
Here is also a snippet from the Symbian docs:
---
Handle-numbers
A handle is a way in which a thread or process can identify an object that is owned or managed by another thread or process. Such objects are Kernel side objects.
A handle uses a number, the handle-number, to identify the associated Kernel side object. The handle, an instance of a RHandleBase derived class, encapsulates the handle-number.
----
I know you in some cases in symbian use a pointer for a handle, when its only used in the same thread, but that is an exception, not a rule...
Forum posts: 110
1. The handle you get from CFbsBitmap::Handle() gives you a handle number for the bitmap and this is used by the Font and Bitmap Server to identify the bitmap. Use the handle to create a duplicate bitmap in the second thread (pass the handle between the threads, not the CFbsBitmap pointer!)
2. The second thread also needs to have a session with the FBs server, otherwise you can't do anything with bitmaps. I think this explains the -34. Call RBsSession::Connect() in the second thread before attempting to duplicate the bitmap or lock the heap.
Forum posts: 2