c - Can we obtain a file descriptor for a semaphore or condition variable? -


i have implementation of bi-directional message channel which, reduce overhead, implemented couple of circular buffers of messages. write 1 end other add pointer message 1 circular buffer , tweak read , write indices it. write in other direction same other buffer , on. code small , simple , avoids overheads of using pipe or fifo, although possibly might have been better solution in ways.

i implemented poll on checking if there message waiting read, , if not doing timed wait on condition variable gets signalled when message added relevant array.

now have application needs wait on socket (more or less) , on message channel @ same time. wish had used fifo or pipe, due overhead in getting code changed (long story), it's not feasible rewrite use fifo or pipe.

is there way file descriptor associated conditional variable? if easier implement poll on 2 file descriptors @ once, 1 conditional variable , 1 socket.

out of curiosity, , making question more useful others similar problem, possible file descriptor associated semaphore poll on semaphore , regular file descriptor @ same time?

generally, no. different oses offer different solutions problem have.

windows

you can associate event socket wsaeventselect , wait waitformultipleobjectsex data on socket or mutex or semaphore event etc.

linux

you can use futex syscall futex_fd argument (however has been removed kernel), or use eventfd implement condition variable.

and can spawn second thread waiting on condition variable, , signal 1 waiting in select(). or ask signals when input received on socket, etc. see this related question.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -