Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
2 questions...
#9
>>1. The main macro exits when it started the last 4 threads. When it exits, sem destructor calls CloseHandle, making the handle invalid and its numeric value >>>subject to use for another handle. If the main thread does not wait until other threads exit, other threads call ReleaseSemaphore with invalid or another >>>(value reused) handle.

I got it, like C++ thread function join().

2, 3. If you know that threads never ever return or throw exception without calling ReleaseSemaphore, then call ReleaseSemaphore at the end instead of atend/#sub. Another way to ensure that ReleaseSemaphore is always called at the end - create a class that calls ReleaseSemaphore in destructor, and declare a variable of that class in the thread.

I think that KISS principle makes me carry on with the old code

#sub ReleaseSem
function sem
ReleaseSemaphore(sem 1 0)

Thanks.


Messages In This Thread
2 questions... - by ldarrambide - 02-09-2019, 08:58 AM
RE: 2 questions... - by Gintaras - 02-09-2019, 09:47 AM
RE: 2 questions... - by ldarrambide - 02-10-2019, 12:18 PM
RE: 2 questions... - by ldarrambide - 02-10-2019, 06:36 PM
RE: 2 questions... - by Gintaras - 02-10-2019, 07:47 PM
RE: 2 questions... - by ldarrambide - 02-10-2019, 07:58 PM
RE: 2 questions... - by Gintaras - 02-11-2019, 06:45 AM
RE: 2 questions... - by Gintaras - 02-11-2019, 07:07 AM
RE: 2 questions... - by ldarrambide - 02-11-2019, 05:19 PM
RE: 2 questions... - by ldarrambide - 02-12-2019, 05:08 PM
RE: 2 questions... - by Gintaras - 02-12-2019, 05:49 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)