ITHREAD crash on ITHREAD_GetResumeCBK | developer.brewmp.com ITHREAD crash on ITHREAD_GetResumeCBK | developer.brewmp.com

Developer

ITHREAD crash on ITHREAD_GetResumeCBK

Forums:

Hello,

I am trying to implement a long blocking function within the ITHREAD context. I have followed several examples, but my applet is crashing on the ITHREAD_GetResumeCBK in the simulator and on the device.
void ssyTestThread(SThreadCtx *stc)
{
AEECallback *pcb;
...
DBGPRINTF("ssyTestThread: %d. call 'GetResumeCBK'...", i);
...
pcb = ITHREAD_GetResumeCBK(stc->pit);

if(pcb == NULL) {
DBGPRINTF("ssyTestThread: %d. ERR: pcb NULL", i);
break;
}

DBGPRINTF("ssyTestThread: %d. call 'Resume'...", i);
ISHELL_Resume(stc->pis, pcb);

DBGPRINTF("ssyTestThread: %d. call 'Suspend'...", i);
ITHREAD_Suspend(stc->pit);

void ssyThreadDone(pMe)
{
SThreadCtx *stc = &pMe->stc;

if(pMe->nThreadResult == SUCCESS) {
DBGPRINTF("ssyTD: Thread exit SUCCESS");
} else {
DBGPRINTF("ssyTD: ERR(%d): Thread exit failed", pMe->nThreadResult);
}
...

void ssyStartThread(pMe)
{
SThreadCtx *stc = &pMe->stc;
int nerr;
int nStackSz = 256;

nerr = ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_THREAD, (void **)&stc->pit);
if(nerr != SUCCESS) {
DBGPRINTF("ssyDPT: ERR(%d): Thread CreateInstance", nerr);
} else {
DBGPRINTF("ssyDPT: Thread CreateInstance SUCCESS");
}
stc->pis = pMe->a.m_pIShell;
stc->pid = pMe->a.m_pIDisplay;
CALLBACK_Init(&pMe->cbThreadDone, (PFNNOTIFY)ssyThreadDone, (void *)pMe);
// pMe->cbThreadDone.pfnCancel = NULL;
// ITHREAD_HoldRsc(stc->pit, (IBase *)pMe->m_pFileMgr);
ITHREAD_Join(stc->pit, &pMe->cbThreadDone, &pMe->nThreadResult);

nerr = ITHREAD_Start(stc->pit, nStackSz, (PFNTHREAD)ssyTestThread, (void *)stc); // pMe);
if(nerr != SUCCESS) {
DBGPRINTF("ssyDPT: ERR(%d): ITHREAD_Start", nerr);
}

The error text in the simulator is:
Unhandled exception at 0x00f0c181 in BREW_Simulator.exe: 0xC0000005: Access violation reading location 0x00f0c181
Also, the thread is usually, but not always returning EPRIVLEVEL (21: Security Violation) in nThreadResult. Do I need to set a privelege level or dependency in the MIF? Any ideas why this code is crashing?

- Thank you, David Manpearl

Problem solved. Operator error. Learned how to yield...

Problem solved. Operator error. Learned how to yield...

Hi David,
Stuck in exactly the same issue....
The ITHREAD_GetResumeCBK is crashing in my application. Checked all the odds but no clue....
Can you please help me out in this notifying what exactly the problem may be.....

Hi David,
Stuck in exactly the same issue....
The ITHREAD_GetResumeCBK is crashing in my application. Checked all the odds but no clue....
Can you please help me out in this notifying what exactly the problem may be.....

Ok, here's the deal with IThreads.
They are not really threads.
ITHREAD simply provides a way to save state while exiting your long processing job for when you return.
If you have a long job to do, the kind of job you'd do in a Thread in J2ME, it is helpful to use the IThread interface. Very helpful. But, the important thing is that you have to call a 'yeild' function every so often within your long processing function or functions.
I found an example that works very well for me. Create this function in your code:
void IThread_Yield(IThread *me, IShell *pIShell)
{
AEECallback *pcb = ITHREAD_GetResumeCBK(me);
ISHELL_Resume( pIShell, pcb );
ITHREAD_Suspend( me );

Then call IThread_Yield periodically in your function. For example, if you are processing a directory full of files, somewhere within your loop (for, while, enumeration, whatever), call IThread_Yield between processing of each file. That will give the system time to do what it needs to do and it will automatically resume your function in the place where it left off. Poor man's bandwidth sharing.
SThreadCtx simply gives you a context structure to fill with whatever callback data you'll need. Follow the various directions and examples and it should be easy. The missing part for me was having to manually yeild. If you don't yield and your function processes for too long... Kaboom!
- Hope this helps! David

Ok, here's the deal with IThreads.
They are not really threads.
ITHREAD simply provides a way to save state while exiting your long processing job for when you return.
If you have a long job to do, the kind of job you'd do in a Thread in J2ME, it is helpful to use the IThread interface. Very helpful. But, the important thing is that you have to call a 'yeild' function every so often within your long processing function or functions.
I found an example that works very well for me. Create this function in your code:
void IThread_Yield(IThread *me, IShell *pIShell)
{
AEECallback *pcb = ITHREAD_GetResumeCBK(me);
ISHELL_Resume( pIShell, pcb );
ITHREAD_Suspend( me );

Then call IThread_Yield periodically in your function. For example, if you are processing a directory full of files, somewhere within your loop (for, while, enumeration, whatever), call IThread_Yield between processing of each file. That will give the system time to do what it needs to do and it will automatically resume your function in the place where it left off. Poor man's bandwidth sharing.
SThreadCtx simply gives you a context structure to fill with whatever callback data you'll need. Follow the various directions and examples and it should be easy. The missing part for me was having to manually yeild. If you don't yield and your function processes for too long... Kaboom!
- Hope this helps! David

Thanks David...
That was really helpful...

Thanks David...
That was really helpful...