What's wrong with the usual way of forking/starting a thread which
blocks itself and writes a byte down a pipe when it's done? That's a
standard generic way of including any blocking behaviour at all into
a select/poll based event loop. Roughly,
void *msg_block(void *arg)
{
struct minfo *m = (struct minfo *)arg;
while (1) {
msgrcv(m->msgid, m->msgbuf, m->msgsz, m->msgflag);
write(m->fd, "*", 1);
}
}
/* main program */
pipe(msg_readfd, msg_writefd);
struct minfo m = { msgid, msgbuf, msgsz, msgflag, msg_writefd };
pthread_t msg_thread;
pthread_create(&msg_thread, 0, msg_block, &m);
...
while (1) {
/* main loop */
...
FD_SET(msg_readfd, &fdset);
select(n, &fdset, 0, 0, 0);
if (FD_ISSET(msg_readfd, &fdset)) {
/* got message in msgbuf */
}
...
}
Add error checking, argument checking, sync for finishing and
seasoning to taste. IMHO, the wart isn't the lack of an event waiting
syscall that copes with different sorts of "descriptor" but the
failure of SysV IPC to provide access to message queues by means of
an ordinary file descriptor in the first place. Even the POSIX.4/1b
mob didn't correct that for their message queues, for some reason.
--Malcolm
-- Malcolm Beattie <mbeattie@sable.ox.ac.uk> Unix Systems Programmer Oxford University Computing Services- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/