?

Log in

No account? Create an account
Paper - brad's life [entries|archive|friends|userinfo]
Brad Fitzpatrick

[ website | bradfitz.com ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Paper [Apr. 28th, 2006|09:15 am]
Brad Fitzpatrick
[Tags|, ]

A Language-Based Approach to Unifying Events and Threads
http://www.cis.upenn.edu/~lipeng/papers/lz06submitted.pdf
This paper presents a language based technique to unify two seemingly opposite programming models for building massively concurrent network services: the event driven model and the multithreaded model. The result is a unified concurrency model providing both thread abstractions and event abstractions.
(via Lamba the Ultimate)

Have only skimmed the paper, need to get to work.... looks cool, though, so I figure I'd beat evan to posting about it. :-)
LinkReply

Comments:
[User Picture]From: loganb
2006-04-28 06:38 pm (UTC)
I'm pretty sure we kicked this idea around on my team at Expedia. They had a totally asynchronous, FSM design in C++ where program flow like:

class Foo {
int requestState;

void State1() {
//Enqueue some I/O operations
}
//Some time later this gets called
void State1Completed() {
//Use results of I/O
return transitionToState2;
}
}

There would be one Foo per request. It allowed for many thousands of transactions to be in flight at once, but it was miserable to code in; error handling was especially difficult.

Instead we wanted to build a system where there was one fiber (user-mode thread) per request and all I/O would be done with completion objects. That is:

String handleRequest() {
//Do some stuff
x = read(); //I/O operation, returns immediately
//Do more stuff
return x.getResult(); //Blocks
}

All I/O under the hood would be asynchronous and the event loop would swap in fibers in and out as they "blocked" on I/O. It is directly analogous to the FSM design. A fiber's stack is equivalent to the FSM "state" (class member variables) and handleRequest() embodies all of the member methods into one function.

Alas, I never had a chance to prototype it and now I work in Java which has no native support for fibers.
(Reply) (Thread)