4 ms·
Events are nothing more than semaphores that cannot count past 1 and clamp; i.e. "binary semaphores". (At least the auto-reset ones.) Microsoft finally added ev
by kazinator 10y ago
Events are nothing more than semaphores that cannot count past 1 and clamp; i.e. "binary semaphores". (At least the auto-reset ones.) Microsoft finally added events that can count past 1 and called them semaphores, under a different API.
If you use this:
HANDLE WINAPI CreateSemaphore(
_In_opt_ LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,
_In_ LONG lInitialCount,
_In_ LONG lMaximumCount,
_In_opt_ LPCTSTR lpName
);
and specify a maximum count of 1, you basically get the same thing as an auto-reset event, under a different API.
Linux has had semaphores in the kernel for ages: see sem_up, sem_down.
The "event" term isn't used as a synonym for a semaphore, like in Win32.
- chadaustin 10y ago"Finally"? Didn't Win95 have CreateSemaphore?
- gruez 10y agoNo? On the MSDN page for CreateSemaphore, it lists the minimum supported client as Windows XP.
- ComputerGuru 10y agoThey cleaned up the MSDN pages (which seems a huge and sad loss of historical data - they should include a history section like man pages), but have a look at the Japanese page: https://msdn.microsoft.com/ja-jp/library/cc429076.aspx?f=255&MSPPError=-2147217396 https://msdn.microsoft.com/ja-jp/library/cc429076.aspx?f=255... It mentions it's supported on Windows 95 and NT 4.0 (On a side note, I'm completely baffled that the metadata for MSDN is not locale-independent In their documentation generation engine/system. I would have thought only the page text would change from one language to another.)
- TillE 10y agoI had to do a bit of programming for NT4 only a few years ago (shudder), and the earliest OS the MSDN docs mentioned was always Windows 2000, even when those functions existed on NT4. Microsoft isn't very interested in maintaining docs about their ancient OSes.
- asveikau 10y agoOf course Linux has had semaphores for a long time. (As has Windows.) I know my way around the Linux kernel pretty well and on the Windows side, I am ex-msft. So I am not learning anything from your scholarly summary here. I mean that eventfd(2) is somewhat more recent and reminds me more of Win32 than the POSIX APIs for this. The API exposes an fd (read: HANDLE) which you can block on with the select/poll/epoll syscalls (read: WaitForMultipleObjects). The comparison could not be more direct. Whereas Unixy APIs and internal-to-linux APIs do not historically reason about synchronization primitives in terms of files. (PS. Manpage for eventfd(2) says you can open it in a semaphore mode.)