When and why were semaphores removed from the rtl?
Mailing lists / fpc-pascal / 2017-07
Semaphores removed from the rtl?
10 messages · 5 people · –
- AAnthony Walter 4
- KKaroly Balogh (Charlie/SGR 2
- MMichael Schnell 2
- BBenjamin Rosseaux 1
- SSven Barth 1
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Hi,
Anthony Walter wroteWhen and why were semaphores removed from the rtl?
They are removed from trunk since Sept 2016, and I think they were deprecated for a while now, although I cannot confirm this. But what's sure, they were only implemented and used interally for Unix. Affected revisions:
https://svn.freepascal.org/cgi-bin/viewvc.cgi?view=revision&revision=28965 https://svn.freepascal.org/cgi-bin/viewvc.cgi?view=revision&revision=34542
The commit messages should explain the whys, I think.
Although the code still has some leftovers here and there, and what's sure, they weren't deprecated with a warning period :(, although I'm not sure they were ever intended for public use... The documentation knows about them at least, and they were public since 2014, but I think even back then this was debated.
Charlie
Thanks for that bit of information Charlie. I should have searched the svn logs.
As a note to this, I am using semaphores quite a bit in SDL2 to guard against things like changes to audio banks in the ui thread and reading audio sample bits in the audio mixer thread, which SDL2 sets up whenever you play audio. There are other places where I use semaphores, but the point is SDL2 implements semaphores across all platforms and they work consistently.
https://wiki.libsdl.org/SDL_CreateSemaphore
It just seems to me like the concept of a semaphore has been well established in CS for decades and it's a bit weird to remove them from the rtl. They are native to all platforms (I just checked). Sure they we not used by any rtl internal functions/objects (in TThread for example), but I don't believe that should have been reason enough to get rid of them.
In other words, just because a one group of developers don't use a tool, that shouldn't dictate its removal.
You could use TPasMPSemaphore from my PasMP project ( https://github.com/BeRo1985/pasmp/ and respectively https://github.com/BeRo1985/pasmp/blob/master/src/PasMP.pas ) which is also cross-platform-capable.
Anthony Walter wrote 25 lines
Nah thanks, I can implement them with native functions on windows, mac, and linux easily enough and with $ifdefs. I am just surprised by the thought process involved in removing them.
Thanks for that bit of information Charlie. I should have searched the svn logs. As a…
Hi,
Anthony Walter wrote 11 lines
They weren't implemented for all platforms in our RTL. Among others, using FPC's Semaphore functions on Windows were resulting in no-ops or Runtime errors (probably the later, I don't have Windows at hand to verify). This is what I mean. I'm not saying they were impossible to implement, just that they never were implemented in FPC RTL, for any platforms except Unices. And they were never intended to appear in the System unit public interface either. (Sadly they have, but that's a different story.)
In other words, just because a one group of developers don't use a tool, that shouldn't dictate its removal.
In this case, those tools were incomplete and unfinished. But I am not arguing against Semaphores as a concept. You are free to implement Semaphore-alike behavior using CriticalSections for example, which are implemented on all platforms which support Threading in the FPC RTL.
Charlie
Nah thanks, I can implement them with native functions on windows, mac, and linux easily…
"Anthony Walter" wroteNah thanks, I can implement them with native functions on windows, mac,
and linux easily enough and with $ifdefs. I am just surprised by the thought process involved in removing them.
As Charlie said, that functionality was never intended for public use and only available for a specific use case.
For cross platform use the Delphi compatible TSemaphore in the SyncObjs unit should be implemented...
Regards,
Sven
Thanks for that bit of information Charlie. I should have searched the svn logs. As a…
Anthony Walter wroteAs a note to this, I am using semaphores quite a bit in SDL2 ...
Do you use Jedi-SDL to combine fpc and SDL ?
-Michael
They weren't implemented for all platforms in our RTL. Among others, using FPC's…
Karoly Balogh wroteYou are free to implement Semaphore-alike behavior using CriticalSections for example, which are implemented on all platforms which support Threading in the FPC RTL.
CriticalSection is the windows-name for Futex, and in Windows (10) the appropriate Library call in fact is a hight performance user space Mutex.
In other environments TCriticalSection is implemented by a "Mutex" system call (supposedly because not all archs / OSes provide "Futex"), and seemingly pthreadlib in Linux (AFAIK) is not intended to be used for this.
Hence, generally, CriticalSection can only be used to construct inter-Thread Semaphores not inter-Process Semaphores.
-Michael
Do you use Jedi-SDL to combine fpc and SDL ? -Michael
Michael, no I don't. I use
https://github.com/sysrpl/Bare.Game/blob/master/source/bare.interop.sdl2.pas
