0

I'm poring a code written (by me) for Windows to other platforms.

I have a generic infrastructure for single-threaded cooperative multitasking, and I try to make it work using POSIX API. This infrastructure allows to wait for any of the specified "events" and handle any of them appropriately. Those "events" include network (sockets), timers, and things induced by the application itself from another thread, such as "event" about queued work item that should be executed in this thread, abort request and etc.

In Windows the natural way to go is using "waitable handles" (events, semaphores and etc.) and WaitForMultipleObjects or equivalent wait function. Sockets can be associated with events as well (WSAEventSelect).

I wonder how I can achieve this using POSIX. What I need is a sort of a wait function, that can be given multiple events/conditions to wait for, including timeout.

Since I need (among other things) sockets, I decided to start from file/socket-specific wait functions, such as select, poll, epoll. And this works as expeced.

Now I wonder how to add "internal" events. One solution I have in mind is creating "artificial" sockets for this viasocketpair, and then send "dummy data" to induce an event in the target thread.

This however seems an overkill and ineffective. Creating sockets seems to be a complex operation. Whereas the only thing that I need is to "wake" a thread.

Any ideas?

valdo
  • 12,632
  • 2
  • 37
  • 67
  • Windows has a richer threading library and POSIX has fewer primitives – David Heffernan Apr 07 '16 at 21:40
  • Are you looking for something like this? http://stackoverflow.com/questions/178114/pthread-like-windows-manual-reset-event – Jim Mischel Apr 08 '16 at 18:37
  • @JimMischel: not exactly. I need a wait function to wait for *multiple* events, and this must include sockets or something triggered by sockets. – valdo Apr 09 '16 at 16:59

0 Answers0