Re: Semaphore and thread
K2G wrote:
Suppose i have created 2 threads and one semaphore with max resource
count 1.
T1 is waiting on Semaphore, so resource count is 0 now.
T2 is also waiting on semaphore . But semaphore is non signled now so
thread is waiting
Now suppose T1 terminates before releasing semaphore,
Uh... You mean, T1 *got* the semaphore (increased its count), and then
ended without releasing the semaphore? Shouldn't the system recognize
that the thread that has the semaphore is now dead and decrease the
count of the semaphore anyway?
Or do you mean T1 is *killed* (by some other thread) before acquiring
the semaphore, while waiting? In that case, shouldn't the wait be
terminated as well?
Is there any way T2 would be able to get the resource ever? Or
resource count of semaphore would be increased anytime?
If it is mutex then T2 could get resource easily as on termination
wait is abandoned.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask