Re: AMIGA will use Linux, but Linux has several

Steve Underwood (steveu@netpage.com.hk)
Wed, 14 Jul 1999 10:23:41 +0000


Hi,

Malcolm Beattie wrote:

> 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.

You just turned one messy piece of IPC into two messy pieces of IPC. Am I
missing some underlying magical elegance in this? It doesn't matter too much if
the message queues work by file descriptors, or by something else, but the damn
things need to be quotable in a select type statement.

Steve

-
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/