Hi,
I have a suggestion for a VDR change: I could use a way to end a cThread externally without having to wait and without hard canceling it.
My thread runs with the usual while (Running()) loop. To signal the loop to stop, it would be enough to set running=false. However, running is a private member of cThread. The only way to set running=false is to call Cancel(). This involves killing the thread and waiting for the thread to terminate. Two things I actually don't want.
There are two ways this could be done. First, by adding a function SoftCancel() { running=false; }. Or second, by modifying Cancel() to just set running=false if called with Cancel(-1) or Cancel(0,false) or similar.
As a workaround I'm now using while (Running() && running2) - which is imho ugly.
Background: I have to terminate several threads at the same time, and calling Cancel(1) sequentially would be a waste of time. I want to set running=false on all threads first, and then cancel the remains later.
Cheers,
Udo
Udo Richter wrote:
Hi,
I have a suggestion for a VDR change: I could use a way to end a cThread externally without having to wait and without hard canceling it.
My thread runs with the usual while (Running()) loop. To signal the loop to stop, it would be enough to set running=false. However, running is a private member of cThread. The only way to set running=false is to call Cancel(). This involves killing the thread and waiting for the thread to terminate. Two things I actually don't want.
There are two ways this could be done. First, by adding a function SoftCancel() { running=false; }. Or second, by modifying Cancel() to just set running=false if called with Cancel(-1) or Cancel(0,false) or similar.
I would prefer using -1 as a special value for this, because this wouldn't require an interface change.
Does the attached patch do what you want?
Klaus
Klaus Schmidinger wrote:
There are two ways this could be done. First, by adding a function SoftCancel() { running=false; }. Or second, by modifying Cancel() to just set running=false if called with Cancel(-1) or Cancel(0,false) or similar.
I would prefer using -1 as a special value for this, because this wouldn't require an interface change.
Agreed. I don't think that someone ever called Cancel(-1) before, so it should be ok to use that.
Btw: This one is shorter and functionally identical:
--- thread.c.old 2006-08-20 16:41:09.273625000 +0200 +++ thread.c 2006-09-24 14:22:59.064500000 +0200 @@ -293,7 +293,7 @@ void cThread::Cancel(int WaitSeconds) { running = false; - if (active) { + if (active && WaitSeconds > -1) { if (WaitSeconds > 0) { for (time_t t0 = time(NULL) + WaitSeconds; time(NULL) < t0; ) { if (!Active())
Cheers,
Udo
Udo Richter wrote:
Klaus Schmidinger wrote:
There are two ways this could be done. First, by adding a function SoftCancel() { running=false; }. Or second, by modifying Cancel() to just set running=false if called with Cancel(-1) or Cancel(0,false) or similar.
I would prefer using -1 as a special value for this, because this wouldn't require an interface change.
Agreed. I don't think that someone ever called Cancel(-1) before, so it should be ok to use that.
Btw: This one is shorter and functionally identical:
--- thread.c.old 2006-08-20 16:41:09.273625000 +0200 +++ thread.c 2006-09-24 14:22:59.064500000 +0200 @@ -293,7 +293,7 @@ void cThread::Cancel(int WaitSeconds) { running = false;
- if (active) {
- if (active && WaitSeconds > -1) { if (WaitSeconds > 0) { for (time_t t0 = time(NULL) + WaitSeconds; time(NULL) < t0; ) { if (!Active())
Well, that's fine with me, too.
I guess you'll also want me to increase the API version number if this goes into version 1.4.4?
Klaus
Klaus Schmidinger wrote:
I guess you'll also want me to increase the API version number if this goes into version 1.4.4?
There's no urgent need from my point, nothing that will be publically available any time soon (if at all), and nothing that should break because of that. And the next APIVERSION bump is probably not that far away anyway. ;)
Cheers,
Udo