[tech] Mac stuff

David Luyer david at luyer.net
Wed Apr 17 23:06:49 WST 2002


Note: This message is primarily about Unix programming, so please ignore
the
subject line :-)

Andrew Bailey writes:

>[0] its a personal peeve of mine if I have to grep the source dir to
find out
>the type of a variable. Like it sucks, pass your vars people please.

I have no problem passing variables, I just find that I often end up
having to
pass them via a void * to do it cleanly -- although I guess then you
still have
a clear typecast back inside the function when you operate that way as
you have
to case the void * to something to use it.

int handler(int fd, void *data);
int timeout_handler(void *data);

add_handler(&(struct pollfd){0, POLLIN, 0}, handler, data);
add_event(&(struct timeval){5, 0}, timeout_handler, data);

Yes:
  1.  squid has changed the way I code, although it's for the better IMO
- my
      code is generally far faster than fork()ing code, and I have taken
      fork()ing servers and achieved insane speedups by applying the
squid
      model (parameterizing the data, and using a poll() or select()
based
      central loop)...
  2.  that's not valid C (unless C has become smarter since I last
looked :-))
  3.  add_handler is required to coalesce different events, and handler
has
      to know what kind of event it's handling

The first thing to learn about Unix programming: fork() is good.
The second thing to learn about Unix programming: fork() is evil.

(and threading vs poll()/select()... both add complexity, you could
argue for
years about the winner, IMO squid+diskd shows who the winner is:
poll()/select()
but with an extra process per disk to hand off blocking disk IO to over
shared
memory ... beats squid asyncio - poll()/select() with threads to hand
off disk
IO ... and beats all "pure" threading attempts at the same problem that
I've
seen to date)

David.



More information about the tech mailing list