SIGEV_THREAD

I don't want to give away the secrets of my future projects until they're closer to the prototype stage, but this most recent personal programming endeavor was going to feature asynchronous io to facilitate my goal of a very efficient, single-machine system, capable of handling hundreds of thousands of simultaneous users.

While flying to and from Las Vegas earlier this week, I worked on coding some simple proof-of-concept tests of various components that were going to be key to such levels of efficiency. The first test was a data structure, and high on the success of that test, I moved on to the async read and write tests.

I got the async reader up and running and later got the async writer coded but when I ran it (hoping to see the output of the writer appear on the reader), I was instead treated to:

EINVAL: Invalid argument

Not what I was hoping for. There really isn't much documentation on the whole AIO system in various unixes, and I didn't have the xnu source on my laptop - so, I couldn't delve into it, to determine which of the many, many parameters was causing this error. The aio_write man page suggested that it could be one of three (very obvious) things; none of which, I determined, were likely the cause.

Defeated, I got my iPhone out and started listening to Weezer until Delta's stupid in-flight movie ended and they started playing my favorite Futurama episode. What are the chances?

Earlier today, I downloaded xnu and got to grep'ing, and found this wonderful snippet in kern_aio.c:

 /* validate aiocb.aio_sigevent.  at this point we only 
  * support sigev_notify equal to SIGEV_SIGNAL or 
  * SIGEV_NONE.  this means sigev_value, sigev_notify_function, 
  * and sigev_notify_attributes are ignored.
  */
  if (entryp->aiocb.aio_sigevent.sigev_notify == SIGEV_SIGNAL) {
    int signum;
    /* make sure we have a valid signal number */
    signum = entryp->aiocb.aio_sigevent.sigev_signo;
    if ( signum <= 0 || signum >= NSIG || 
      signum == SIGKILL || signum == SIGSTOP )
      return (EINVAL);
  }
  else if (entryp->aiocb.aio_sigevent.sigev_notify != SIGEV_NONE)
    return (EINVAL);

The comment text says it all, really: no SIGEV_THREAD support. I was bummed for a little while, because I really wanted to use AIO in this project. I think my threading model will do just fine with blocking IO where a single thread reads and a single thread writes - which should be plenty fast, but not nearly as cool. Oh well.

Subscribe to A garage sale for your mind

Don’t miss out on the latest posts. Sign up now to get access to the library of members-only posts.
[email protected]
Subscribe