Are there any forms of synchronization in Windows that can be used with select() (other than sockets)? For example, Linux has eventfd
Asked
Active
Viewed 787 times
1 Answers
2
The Windows socket implementation aligns to BSD sockets, while there are also Windows specific synchronization functions (I assume, the Windows socket implementation uses them internally).
Have a look at the Create*()
functions for waitable object types like mutexes, semaphores, spinlocks, events and timers (since Windows XP) and use the following along with type specific functions:
-
Waits until the specified object is in the signaled state or the time-out interval elapses.
-
Waits until one or all of the specified objects are in the signaled state or the time-out interval elapses.
WaitForMultipleObjects()
could be regarded as an equivalent to select()
when using HANDLE
s
-
4And by using `WSAEventSelect`, socket events can be multiplexed with events from other HANDLE types. – Ben Voigt Jan 21 '14 at 20:16
-
Watch out - for high perf servers these wait functions are limited to 64 handles and so this is not the optimal way – paulm Jan 21 '14 at 20:25
-
@paulm: Good point. But what is the optimal way? Depending on the actual scenario, there may be blocking queues (despite the backlog for incoming connections), N threads for M<=64 HANDLEs or direct callbacks. A service might just run efficiently, if HANDLEs are bound to extensive tasks. – Sam Jan 21 '14 at 20:52
-
@paulm: The recommended way of waiting on more than 64 simultaneous handles is to spawn a bunch of threads which wait on up to 64 handles each and then signal an event when done; the main thread then waits for those events. Of course, spawning threads isn't cheap, so that doesn't scale to very large numbers of handles. When you've got thousands of handles, those are usually all sockets, in which case the vanilla `select()` works just fine. – Adam Rosenfield Jan 22 '14 at 20:23
-
To get the best performance on win32 with a significant amount of sockets you should use IO Completion ports. I don't know how select() on win32 works, I'd guess it uses WaitForMultipleObjects() internally. – paulm Jan 23 '14 at 10:21
-
http://stackoverflow.com/questions/754068/win32-overlapped-i-o-completion-routines-or-waitformultipleobjects – paulm Jan 23 '14 at 10:23