How to make a blocking function | developer.brewmp.com How to make a blocking function | developer.brewmp.com

Developer

How to make a blocking function

Forums:

Hi,
I have code that creates a TCP socket, using the standard BREW callbacks mechanism.

However, I need to create the same but only from a blocking function. This blocking function would not return until the TCP socket was created.

How do I do this on BREW?

I am running on one Thread and the BREW system runs on another Thread. So I need to block my current Thread to allow BREW system to run and call my callbacks..

Any help would be appreciated

If you look in src/thrdutil you'll find example code for stuff like yielding threads.

If you look in src/thrdutil you'll find example code for stuff like yielding threads.

I've seen that. Thanks!
Few questions about the usage:
1. The function requires a handle to an IThread. So to use that I need to create my own IThread?
2. Does t also mean that the IThread on which I call Yield, has to be the one I have a handle to (meaning, the IThread that I created)?
3. How do I know when to stop calling Yield, in the waiting IThread? Is there something like a semphore? or do I set a boolean flag somewhere?
Last question... :->
Is there a limitation on using the same Interface instance, but from different IThreads? For example, to create an ISockPort in the app primordial IThread and issue its asynchronous operation (e.g., ISOCKPORT_ReadV) on another IThread?
(I'm asking this because there is such limitation in Symbian OS...)
Thanks!

I've seen that. Thanks!
Few questions about the usage:
1. The function requires a handle to an IThread. So to use that I need to create my own IThread?
2. Does t also mean that the IThread on which I call Yield, has to be the one I have a handle to (meaning, the IThread that I created)?
3. How do I know when to stop calling Yield, in the waiting IThread? Is there something like a semphore? or do I set a boolean flag somewhere?
Last question... :->
Is there a limitation on using the same Interface instance, but from different IThreads? For example, to create an ISockPort in the app primordial IThread and issue its asynchronous operation (e.g., ISOCKPORT_ReadV) on another IThread?
(I'm asking this because there is such limitation in Symbian OS...)
Thanks!

roey wrote:I've seen that. Thanks!
Few questions about the usage:
1. The function requires a handle to an IThread. So to use that I need to create my own IThread?
2. Does t also mean that the IThread on which I call Yield, has to be the one I have a handle to (meaning, the IThread that I created)?
3. How do I know when to stop calling Yield, in the waiting IThread? Is there something like a semphore? or do I set a boolean flag somewhere?
Last question... :->
Is there a limitation on using the same Interface instance, but from different IThreads? For example, to create an ISockPort in the app primordial IThread and issue its asynchronous operation (e.g., ISOCKPORT_ReadV) on another IThread?
(I'm asking this because there is such limitation in Symbian OS...)
Thanks!
To your questions:
1. Yes. You need to create your own thread and the handle is IThread pointer.
2. Yes. Actually, Yield() calls ITHREAD_Suspend() to suspend and Register a resume callback.
3. Because BREW only uses co-operative threading, you don't really need a semaphore. You can use a boolean flag to control your program flow.
I suggest you to read files in \sdk\src\thrdutil\, and you'll understand more.
For the Symbian question, because the symbian main thread lives in a framework, but the other thread doesn't. The other thread doesn't have access to the framework. But if your doesn't need the framework to do your work, you can construct your objects (Active scheduler, Push/Pop stack, and other things), and use them in the thread for sure. But in BREW, you don't have this problem, because IThread is not like the thread in Symbian. It is like a Multi-Task scheme, rather than Multi-Threading... In other words, it's a single thread, but allow you to switch between tasks.

roey wrote:I've seen that. Thanks!
Few questions about the usage:
1. The function requires a handle to an IThread. So to use that I need to create my own IThread?
2. Does t also mean that the IThread on which I call Yield, has to be the one I have a handle to (meaning, the IThread that I created)?
3. How do I know when to stop calling Yield, in the waiting IThread? Is there something like a semphore? or do I set a boolean flag somewhere?
Last question... :->
Is there a limitation on using the same Interface instance, but from different IThreads? For example, to create an ISockPort in the app primordial IThread and issue its asynchronous operation (e.g., ISOCKPORT_ReadV) on another IThread?
(I'm asking this because there is such limitation in Symbian OS...)
Thanks!
To your questions:
1. Yes. You need to create your own thread and the handle is IThread pointer.
2. Yes. Actually, Yield() calls ITHREAD_Suspend() to suspend and Register a resume callback.
3. Because BREW only uses co-operative threading, you don't really need a semaphore. You can use a boolean flag to control your program flow.
I suggest you to read files in \sdk\src\thrdutil\, and you'll understand more.
For the Symbian question, because the symbian main thread lives in a framework, but the other thread doesn't. The other thread doesn't have access to the framework. But if your doesn't need the framework to do your work, you can construct your objects (Active scheduler, Push/Pop stack, and other things), and use them in the thread for sure. But in BREW, you don't have this problem, because IThread is not like the thread in Symbian. It is like a Multi-Task scheme, rather than Multi-Threading... In other words, it's a single thread, but allow you to switch between tasks.