Tatsuyuki Ishi
2016-12-09 09:59:56 UTC
Relying on too much mutexes isn't a good idea. Some atomic mechanics should
be involved.
1. epoll, kqueue, IOCP, /dev/poll are all edge-triggered, and AFAIK they
are threadsafe.
Side notes:
Time to ditch select(). Who use it?
Switching to GetQueuedCompletionStatusEx allows us to use the same scheme
for UNIX and Windows (IOCP). It's more important to reduce system calls
than to reduce mutex locks. XP? Nobody updates software on an unsupported
OS.
2. Switch to atomic MPMC queue.
This one <https://github.com/cameron314/concurrentqueue> seems handy.
3. Polling method: poll a bunch, pick one, push the others to queue.
Order: poll -> queue -> block
Conclusion:
Most system calls do synchronization in kernel-level which is way cheaper
(they cheat using privileged instructions). The global lock is not a good
idea on highly-concurrent system, and anyway atomic instructions is always
better. We should minimize userland mutex usage and enable parallel polling
instead.
be involved.
1. epoll, kqueue, IOCP, /dev/poll are all edge-triggered, and AFAIK they
are threadsafe.
Side notes:
Time to ditch select(). Who use it?
Switching to GetQueuedCompletionStatusEx allows us to use the same scheme
for UNIX and Windows (IOCP). It's more important to reduce system calls
than to reduce mutex locks. XP? Nobody updates software on an unsupported
OS.
2. Switch to atomic MPMC queue.
This one <https://github.com/cameron314/concurrentqueue> seems handy.
3. Polling method: poll a bunch, pick one, push the others to queue.
Order: poll -> queue -> block
Conclusion:
Most system calls do synchronization in kernel-level which is way cheaper
(they cheat using privileged instructions). The global lock is not a good
idea on highly-concurrent system, and anyway atomic instructions is always
better. We should minimize userland mutex usage and enable parallel polling
instead.