[vdr] Eggtimer-0.9.1 thread won't end

Peter Juszack vdr at unterbrecher.de
Fri Mar 24 13:29:11 CET 2006


Stefan Huelswitt wrote:
> On 24 Mar 2006 Peter Juszack <vdr at unterbrecher.de> wrote:
>
>   
>> Do I have to lock/unlock the cDevice when switching to a channel?
>>     
>
> I don't know this specific plugin, but looking at the code
> sniplet:
>
>   
>> void cEggtimerThread::Stop(void) {
>> #ifdef DEBUG
>>         printf("cEggtimerThread::Stop\n" );
>> #endif
>>         running = false;
>>         Cancel(30);
>> }
>>
>>
>> void cEggtimerThread::Action(void) {
>>     
>
> [...]
>
>   
>>                     Stop(); // Stop eggtimer thread
>>     
>
> I don't think that one should Cancel() (in this case via Stop())
> a thread from inside the Action() function.
> This must lead to the observed dead-lock.
>
> I guess you should set running=false and let the loop terminate
> itself (if needed you can break; out from the loop too). On exit
> from Action() the child thread is terminated.
>
> Regards.
>
>   
Thats the point. I already fixed it. I also removed the running variable 
because
cThread already has a private member named running.
I decided not to declare any running/active variables at all in my 
derived class
but to use the Running() mehtod of cThread.
To leave the action loop from within I just defined a variable leaveLoop 
locally
in the Action method.

bool leaveLoop = false;

while (Running() && !leaveLoop) {
    ... do it
   
    if ( threadShouldEnd )
       leaveLoop = true;
}

I know that it would be possible to leave the Action mehtod via return. 
But I want
to implement some clean up at after the action loop so the method must 
finish
in al cases.

I don't understand why it is not possible to set the cThread::running 
member to false
from within the action loop or use any other cThread implemented 
mechnism to leave
the action loop.
Leaving this to the plugin developer is not the best idea beacause of 
duplicate running variables.

Regards Peter







More information about the vdr mailing list