Anyone have any idea why someone would do this? (mtxScrub is a mutex handle....)

Anyone have any idea why someone would do this?  (mtxScrub is a mutex handle....)

destructor TDataServer.Destroy;
var
  ii : integer;
begin
  for ii:=1 to 100 do
  begin
    try
      CloseHandle(mtxScrub);
      break;
    except
      sleep(100);
    end;
  end;
  inherited Destroy;
end;

Comments

  1. Because they are a plank? Its obvious they gave it 100 tries to close the mutex, seems excessive..... Just a bit

    ReplyDelete
  2. Perhaps the Mutex is held by another thread, and you are waiting to give it a fair chance to end before you move on?

    ReplyDelete
  3. Slow afternoon, nothing better to do?

    ReplyDelete
  4. It should, but it can't if it is held - hence the exception handling.  Hard to understand the motivation for this, without knowing the whole picture.  I wonder, is there another piece of code with a try/except around that mutex somewhere? Edit: A lot of issues with threads that have concurrency, is about the chicken vs the egg story.  Who got there first?

    ReplyDelete

Post a Comment