Forum > Beginners

Polling a semaphore

(1/5) > >>

joho:
Is there any way to check the state of a Semaphore without actually blocking a thread?

I mean those semaphores used with SemaphorePost / SemaphoreWait / and so on.

I just want  to check if it exists, I do not want to block the thread or create it, etc.

kapibara:
A counting semaphore? You could try this: InterlockedSemaphoreDemo.zip from the thread below contains a unit with a semaphore class. Add the overloaded wait() function from the last message of the thread to the semaphore. If you call wait() now and use something like zero as an argument and the semaphore returns false, it should mean no slots where available at that moment. Untested, no guarantees..

http://forum.lazarus.freepascal.org/index.php/topic,29197.msg221453.html#msg221453

PS. I remember FD from the 90's. Bra grejer..

taazz:

--- Quote from: joho on October 09, 2017, 01:48:24 am ---Is there any way to check the state of a Semaphore without actually blocking a thread?

I mean those semaphores used with SemaphorePost / SemaphoreWait / and so on.

I just want  to check if it exists, I do not want to block the thread or create it, etc.

--- End quote ---
If you are talking for the synchronizing kind of semaphores then https://youtu.be/RaEUw107dpg?t=805

joho:

--- Quote from: kapibara on October 09, 2017, 05:13:34 am ---A counting semaphore? You could try this: InterlockedSemaphoreDemo.zip from the thread below contains a unit with a semaphore class.

http://forum.lazarus.freepascal.org/index.php/topic,29197.msg221453.html#msg221453

PS. I remember FD from the 90's. Bra grejer..

--- End quote ---

Yes, something like that. Thank you.

(Porting code from OS/2 to Win32, it's so interesting to see how much is still the same :))

(Tack! Jag skall försöka göra något roligt med det nu också! :))

joho:

--- Quote from: taazz on October 09, 2017, 05:44:35 am ---
--- Quote from: joho on October 09, 2017, 01:48:24 am ---Is there any way to check the state of a Semaphore without actually blocking a thread?

I mean those semaphores used with SemaphorePost / SemaphoreWait / and so on.

I just want  to check if it exists, I do not want to block the thread or create it, etc.

--- End quote ---
If you are talking for the synchronizing kind of semaphores then https://youtu.be/RaEUw107dpg?t=805

--- End quote ---

Thanks.

Well .. the semaphores that seem to exist in FPC look good, but I needed a way to see if one was set without actually blocking my thread. I just want to do something based on that.

Navigation

[0] Message Index

[#] Next page

Go to full version