IThread Blocking | developer.brewmp.com IThread Blocking | developer.brewmp.com

Developer

IThread Blocking

Forums:

I've been experimenting with IThread lately, and I ran into a few issues regarding EVT_SUSPEND/EVT_RESUME handling.

Upon an EVT_SUSPEND, how do a thread be into a permanent sleep state until it is awken by code in EVT_RESUME?

AEECallback *pcb = ITHREAD_GetResumeCBK(thread);
ISHELL_Resume(m_pIShell,pcb);
SHELL_SetTimerEx(m_pIShell,1000,pcb);
ITHREAD_Suspend(thread);

What would be a safe way to cancel the timer? I noticed that calling pcb->pfnCancel(pcb) does not make the thread resume at Suspend. Calling pfnNotify right after pfnCancel seemed to work, but I am not sure.

Essentially, how do I have a thread stayed suspended indefinitely until the AEECallback is activated with a pfnNotify call?

Thanks...

I meant, EVT_APP_SUSPEND/EVT_APP_RESUME.
brewisv wrote:I've been experimenting with IThread lately, and I ran into a few issues regarding EVT_SUSPEND/EVT_RESUME handling.
Upon an EVT_SUSPEND, how do a thread be into a permanent sleep state until it is awken by code in EVT_RESUME?
AEECallback *pcb = ITHREAD_GetResumeCBK(thread);
ISHELL_Resume(m_pIShell,pcb);
SHELL_SetTimerEx(m_pIShell,1000,pcb);
ITHREAD_Suspend(thread);
What would be a safe way to cancel the timer? I noticed that calling pcb->pfnCancel(pcb) does not make the thread resume at Suspend. Calling pfnNotify right after pfnCancel seemed to work, but I am not sure.
Essentially, how do I have a thread stayed suspended indefinitely until the AEECallback is activated with a pfnNotify call?
Thanks...

I meant, EVT_APP_SUSPEND/EVT_APP_RESUME.
brewisv wrote:I've been experimenting with IThread lately, and I ran into a few issues regarding EVT_SUSPEND/EVT_RESUME handling.
Upon an EVT_SUSPEND, how do a thread be into a permanent sleep state until it is awken by code in EVT_RESUME?
AEECallback *pcb = ITHREAD_GetResumeCBK(thread);
ISHELL_Resume(m_pIShell,pcb);
SHELL_SetTimerEx(m_pIShell,1000,pcb);
ITHREAD_Suspend(thread);
What would be a safe way to cancel the timer? I noticed that calling pcb->pfnCancel(pcb) does not make the thread resume at Suspend. Calling pfnNotify right after pfnCancel seemed to work, but I am not sure.
Essentially, how do I have a thread stayed suspended indefinitely until the AEECallback is activated with a pfnNotify call?
Thanks...

Just do this...
ITHREAD_GetResumeCBK
.. give the callback to whoever you want to wake you up later on - i.e. the main app handler for EVT_RESUME
ITHREAD_Suspend

Just do this...
ITHREAD_GetResumeCBK
.. give the callback to whoever you want to wake you up later on - i.e. the main app handler for EVT_RESUME
ITHREAD_Suspend

brewisv wrote:I've been experimenting with IThread lately, and I ran into a few issues regarding EVT_SUSPEND/EVT_RESUME handling.
Upon an EVT_SUSPEND, how do a thread be into a permanent sleep state until it is awken by code in EVT_RESUME?
AEECallback *pcb = ITHREAD_GetResumeCBK(thread);
ISHELL_Resume(m_pIShell,pcb);
SHELL_SetTimerEx(m_pIShell,1000,pcb);
ITHREAD_Suspend(thread);
What would be a safe way to cancel the timer? I noticed that calling pcb->pfnCancel(pcb) does not make the thread resume at Suspend. Calling pfnNotify right after pfnCancel seemed to work, but I am not sure.
Essentially, how do I have a thread stayed suspended indefinitely until the AEECallback is activated with a pfnNotify call?
Thanks...
the callback you get from ITHREAD_GetResumeCBK is the same as an any other callback in that you can pass it to any function capable of taking a callback. Ergo, it really should work (and does, because you've tried it). It sounds perfectly safe to me.
Caveat- read my later post.

brewisv wrote:I've been experimenting with IThread lately, and I ran into a few issues regarding EVT_SUSPEND/EVT_RESUME handling.
Upon an EVT_SUSPEND, how do a thread be into a permanent sleep state until it is awken by code in EVT_RESUME?
AEECallback *pcb = ITHREAD_GetResumeCBK(thread);
ISHELL_Resume(m_pIShell,pcb);
SHELL_SetTimerEx(m_pIShell,1000,pcb);
ITHREAD_Suspend(thread);
What would be a safe way to cancel the timer? I noticed that calling pcb->pfnCancel(pcb) does not make the thread resume at Suspend. Calling pfnNotify right after pfnCancel seemed to work, but I am not sure.
Essentially, how do I have a thread stayed suspended indefinitely until the AEECallback is activated with a pfnNotify call?
Thanks...
the callback you get from ITHREAD_GetResumeCBK is the same as an any other callback in that you can pass it to any function capable of taking a callback. Ergo, it really should work (and does, because you've tried it). It sounds perfectly safe to me.
Caveat- read my later post.

If you look in src/thrdutil in the SDK you'll find an example of cancelling a thread callback by calling pfnCancel - i.e exactly what you want to do.

If you look in src/thrdutil in the SDK you'll find an example of cancelling a thread callback by calling pfnCancel - i.e exactly what you want to do.

BenBlaukopf wrote:If you look in src/thrdutil in the SDK you'll find an example of cancelling a thread callback by calling pfnCancel - i.e exactly what you want to do.
Essentially, I'd like my thread to stay suspended until a certain condition is met. That is, thread A needs to stay suspended until another thread "wakes/signals" it to resume execution.
I think the function void AEECondVarTimedWaitCancel(AEECallback *pcb) is what I need, but I can't grok it after reading its source :confused:
I'd like to avoid "busy wait" if possible.

BenBlaukopf wrote:If you look in src/thrdutil in the SDK you'll find an example of cancelling a thread callback by calling pfnCancel - i.e exactly what you want to do.
Essentially, I'd like my thread to stay suspended until a certain condition is met. That is, thread A needs to stay suspended until another thread "wakes/signals" it to resume execution.
I think the function void AEECondVarTimedWaitCancel(AEECallback *pcb) is what I need, but I can't grok it after reading its source :confused:
I'd like to avoid "busy wait" if possible.

Sure - a busy wait isn't going to be compatible with suspend. But it sounds like you've got everything you need.
I just reread your original post as I was in the middle of an airport and a long day of travel the first time, and I missed a few things.
AEECallback *pcb = ITHREAD_GetResumeCBK(thread);
ISHELL_Resume(m_pIShell,pcb);
SHELL_SetTimerEx(m_pIShell,1000,pcb);
ITHREAD_Suspend(thread);
What's the ISHELL_Resume for? The ISHELL_SetTimerEx does everything you need.
You just need to make sure that your handled of EVT_APP_SUSPEND cancels the callback (use CALLBACK_Cancel, as per the example in src/thrdutil/AEETU_Mutex.c::AEEMUtexGrab - and then sets it up again on EVT_APP_RESUME; whether by ISHELL_Resume or ISHELL_SetTimerEx is up to you. I don't think calling pfnNotify directly is sensible, as you will be resuming the thread within your main applications stack context, not the thread's stack context!

Sure - a busy wait isn't going to be compatible with suspend. But it sounds like you've got everything you need.
I just reread your original post as I was in the middle of an airport and a long day of travel the first time, and I missed a few things.
AEECallback *pcb = ITHREAD_GetResumeCBK(thread);
ISHELL_Resume(m_pIShell,pcb);
SHELL_SetTimerEx(m_pIShell,1000,pcb);
ITHREAD_Suspend(thread);
What's the ISHELL_Resume for? The ISHELL_SetTimerEx does everything you need.
You just need to make sure that your handled of EVT_APP_SUSPEND cancels the callback (use CALLBACK_Cancel, as per the example in src/thrdutil/AEETU_Mutex.c::AEEMUtexGrab - and then sets it up again on EVT_APP_RESUME; whether by ISHELL_Resume or ISHELL_SetTimerEx is up to you. I don't think calling pfnNotify directly is sensible, as you will be resuming the thread within your main applications stack context, not the thread's stack context!

BenBlaukopf wrote:Sure - a busy wait isn't going to be compatible with suspend. But it sounds like you've got everything you need.
I just reread your original post as I was in the middle of an airport and a long day of travel the first time, and I missed a few things.
AEECallback *pcb = ITHREAD_GetResumeCBK(thread);
ISHELL_Resume(m_pIShell,pcb);
SHELL_SetTimerEx(m_pIShell,1000,pcb);
ITHREAD_Suspend(thread);
What's the ISHELL_Resume for? The ISHELL_SetTimerEx does everything you need.
You just need to make sure that your handled of EVT_APP_SUSPEND cancels the callback (use CALLBACK_Cancel, as per the example in src/thrdutil/AEETU_Mutex.c::AEEMUtexGrab - and then sets it up again on EVT_APP_RESUME; whether by ISHELL_Resume or ISHELL_SetTimerEx is up to you. I don't think calling pfnNotify directly is sensible, as you will be resuming the thread within your main applications stack context, not the thread's stack context!
You are right. I don't need the "extra" ISHELL_Resume() before calling the timer. I checked out AEETU_Mutex.c::AEEMUtexGrab, but I can't see how to resume my thread without calling pfnNotify. My callback has already been cancelled with CALLBACK_Cancel, so which callback do I use for ISHELL_Resume?

BenBlaukopf wrote:Sure - a busy wait isn't going to be compatible with suspend. But it sounds like you've got everything you need.
I just reread your original post as I was in the middle of an airport and a long day of travel the first time, and I missed a few things.
AEECallback *pcb = ITHREAD_GetResumeCBK(thread);
ISHELL_Resume(m_pIShell,pcb);
SHELL_SetTimerEx(m_pIShell,1000,pcb);
ITHREAD_Suspend(thread);
What's the ISHELL_Resume for? The ISHELL_SetTimerEx does everything you need.
You just need to make sure that your handled of EVT_APP_SUSPEND cancels the callback (use CALLBACK_Cancel, as per the example in src/thrdutil/AEETU_Mutex.c::AEEMUtexGrab - and then sets it up again on EVT_APP_RESUME; whether by ISHELL_Resume or ISHELL_SetTimerEx is up to you. I don't think calling pfnNotify directly is sensible, as you will be resuming the thread within your main applications stack context, not the thread's stack context!
You are right. I don't need the "extra" ISHELL_Resume() before calling the timer. I checked out AEETU_Mutex.c::AEEMUtexGrab, but I can't see how to resume my thread without calling pfnNotify. My callback has already been cancelled with CALLBACK_Cancel, so which callback do I use for ISHELL_Resume?

Set pfnCancel to NULL, and call then ISHELL_Resume.

Set pfnCancel to NULL, and call then ISHELL_Resume.

brewisv wrote:You are right. I don't need the "extra" ISHELL_Resume() before calling the timer. I checked out AEETU_Mutex.c::AEEMUtexGrab, but I can't see how to resume my thread without calling pfnNotify. My callback has already been cancelled with CALLBACK_Cancel, so which callback do I use for ISHELL_Resume?
just use the same callback....

brewisv wrote:You are right. I don't need the "extra" ISHELL_Resume() before calling the timer. I checked out AEETU_Mutex.c::AEEMUtexGrab, but I can't see how to resume my thread without calling pfnNotify. My callback has already been cancelled with CALLBACK_Cancel, so which callback do I use for ISHELL_Resume?
just use the same callback....