A long sync operation in a service prevents other event processing and leads to device crash | developer.brewmp.com A long sync operation in a service prevents other event processing and leads to device crash | developer.brewmp.com

Developer

A long sync operation in a service prevents other event processing and leads to device crash

Forums:

Hi,

 

I need to perform a long sync operation.

Since it's impossible to do in an app I decided to try using a service. Since it's supposed to run in a separate thread.

Following is what I did:

1) Extended the service sample app by adding a timered task using ISysTimer.
2) Upon the timed signal I created an endless loop which periodically prints debug messages.
3) While the loop is running I'm pressing keys on the device/simulator and not getting the events (device eventually crshed).

Questions:
1) Is that how it supposed to be or did I miss something?
2) If I understood correctly, in the future (BMP 1.1.x) I will be able to create service in other processes besides the kernel.
Will this solve my problem?

 

Thanks a lot,

                   Eli

 

It seems your endless loop is causing the watch dog timeout. If you have possibility to split your job then please try to use below suggestion to avoid dog timeout.
#define TIMER_Delay XX   //timer between each computation to save from watch dog
int  Iteration=0; // keep some counter
foo(){.............please break your sync operations into few partsfirst part of computationIteration++;..........if(Iteration == Some_num ) {//break from here to save from watch dogISHELL_SetTimer(pMe->pIShell, TIMER_Delay ,pfn, (void*)pUser);}elseif(Iteration == Some_anothernum ) {//break from here to save from watch dogISHELL_SetTimer(pMe->pIShell, TIMER_Delay ,pfn, (void*)pUser);
}........}
There are multiple  methods to do this same task, you can also use events or signals to do this same job. You can use ISysTimer_SetDelay and then ISignalQ_Pop, ISignalCtl_Enable.
Please refer to API doc for more details about ISignalQ_Pop and ISignalCtl_Enable.

It seems your endless loop is causing the watch dog timeout. If you have possibility to split your job then please try to use below suggestion to avoid dog timeout.
#define TIMER_Delay XX   //timer between each computation to save from watch dog
int  Iteration=0; // keep some counter
foo(){.............please break your sync operations into few partsfirst part of computationIteration++;..........if(Iteration == Some_num ) {//break from here to save from watch dogISHELL_SetTimer(pMe->pIShell, TIMER_Delay ,pfn, (void*)pUser);}elseif(Iteration == Some_anothernum ) {//break from here to save from watch dogISHELL_SetTimer(pMe->pIShell, TIMER_Delay ,pfn, (void*)pUser);
}........}
There are multiple  methods to do this same task, you can also use events or signals to do this same job. You can use ISysTimer_SetDelay and then ISignalQ_Pop, ISignalCtl_Enable.
Please refer to API doc for more details about ISignalQ_Pop and ISignalCtl_Enable.

I would prefer using IDispatcher's Resume or Timer methods to chop up a long running operation.

I would prefer using IDispatcher's Resume or Timer methods to chop up a long running operation.

It's not really a good programming practice to implement a infinite loop that never yields. You should always rely on timers, signals or IThread (see https://developer.brewmp.com/resources/how-to/using-ithread).

It's not really a good programming practice to implement a infinite loop that never yields. You should always rely on timers, signals or IThread (see https://developer.brewmp.com/resources/how-to/using-ithread).

.

.