DenkzeitWiki

Suchen:

Aktuelle Änderungen Printable View Änderungen Bearbeiten

ConditionSystems > Conditions > InformationSchema > GarbageCollection > RecentChanges > IPython > YukihiroMatsumoto > TestDrivenClojure > MatthiasFelleisen > CheckedExceptions > Exceptions > HungarianNotation > HackersAndPainters > JustInTimeCompiler > FunctionalLanguage > FunctionalProgramming > EscapeTheEventLoopClear Trail
Main /

Escape The Event Loop

CoRoutines
TrampolineStyle



To be fair, there are good reasons for the popularity of the synchronous style. APIs that don't return until they've done what you asked them to do are usually simpler than the asynchronous alternatives. They require less code to use. The code is typically also a lot easier to read, because the flow of the code directly reflects the sequencing of operations; asynchronous code tends to have a somewhat fragmented structure. And of course sequential code is a lot easier to get right - doing everything on one thread in the order you want is much easier to do than trying to write code that handles events in whatever order they happen to occur, with whatever thread they choose to arrive on.

As for receiving data, that is initiated by the network card - when it receives a packet, it raises an interrupt. This causes the CPU to stop what it's doing and handle the interrupt. Exactly what happens at this point will vary depending on the exact context, but the important point is that the handling of incoming data is triggered by the arrival of incoming data. There doesn't need to be a thread waiting to receive the data. The data just arrives, and by the magic of interrupts, suitable processing ensues.





Now instead of a tedious kind of state machine, you're writing an plain, ordinary function that sends messages to its peer and looks at the response, as though that were all synchronous, and it's so much simpler. Yet the execution underneath that isn't synchronous at all, because your computation is suspended in between your send and the response. It really does return every time it sends a message, it just starts up next time where it left off. [1]




Edit - BackLinks - Tags - Page Hist - Print - Changes - Home - Orphans - Help

Zuletzt geändert am 11.03.2007 22:39 Uhr und seit 7. April 2005 982 aufgerufen.