[RFE] Soft-cancel cThread

Message ID 451679DA.8040202@gmx.de
State New
Headers

Commit Message

Udo Richter Sept. 24, 2006, 12:28 p.m. UTC
  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:




Cheers,

Udo
  

Comments

Klaus Schmidinger Sept. 24, 2006, 12:56 p.m. UTC | #1
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
  
Udo Richter Sept. 24, 2006, 9:21 p.m. UTC | #2
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
  

Patch

--- 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())