Cooperative Task Management without Manual Stack Management
- r, Event-driven Programming is Not the Opposite of Threaded Programming
Cooperative Task Management without Manual Stack Management or, - - PowerPoint PPT Presentation
Cooperative Task Management without Manual Stack Management or, Event-driven Programming is Not the Opposite of Threaded Programming Atul Adya, Jon Howell, Marvin Theimer, William J. Bolosky, John R. Douceur Microsoft Research Presented by Li
2
– People think “event-driven” programming is the opposite of “multithreaded” programming. – Combination of these two styles has some problems.
– We can combine these two styles, with concerning two issues. – Provide an approach to solving these problems.
4
– Execution of tasks can interleave on uniprocessor or overlap on multiprocessor – Efficient but has race conditions
– Executes tasks without any interleavings – No race condition but inefficient, e.g blocking on I/O
– A task code only yields control to other tasks at well-defined point in its execution – Preserves the advantages of Preemptive and serial task management
A B B A A A B A B A
I/O I/O complete
Preemptive Serial Cooperative
– With ASM, the programmer expresses each complete task as a single procedure in the source language – It is associated with the style “multithreaded” programming
– MSM requires a programmer to rip the code for any given task into event handlers – Event handlers are procedures that respond to the events – It is associated with the style “event-driven” programming
P() I/O I/O completes I/O A procedure p with ASM A procedure P with its two event handlers P1, P2, by MSM P1() P2()
Stack Management Task Management Cooperative Preemptive Manual Automatic Event-driven Multithreaded Sweet spot
No Not Oppo possit ite
– Affect on program structures – Introduce more rules about semantics – Software evolution exacerbates this problem
– Callee procedure as yielding affects the property of caller procedure – Software evolution bring such a problem
11
– Combines their advantages and avoid their disadvantages – In software development, programmers working on a same project can use what ever styles they like
– The code with MSM calls the code with ASM (MSM calls ASM) – The code with ASM calls the code with MSM (ASM calls MSM)
P1 F() I/O F() P2
handler P1, and P2.
Both th P P and F block ck
I/ I/O ! !
P F1 F2 P
handlers, including I/O operations,
P
Immediate ately Return rn to P P o
F1 1 f finishes Second re retu turn to to P P afte after F2 f 2 finish shes es I I/O c complet etion . .
I/O
I/O Completetion
Use e some glue code e that can connec ect them smoothly … y …
Code with ASM Code with MSM Adaptor
P1 F() I/O F() P2
handler P1, and P2.
P1 F() I/O F() P2
Adaptor Adaptor
P1
Ad Adap aptor r fo fork rk a a new thre thread an and exe xecu cute F F
it. t. The e control can be sched edule e back ck. F F cal calls back ack adptor, w with P2, handler er.
P F1 F2 P
handlers, including I/O operations,
P
I/O
I/O Completetion
P F1 F2 P
Adaptor Adaptor
I/O
Adaptor
Adaptor c calls F1 1 inst stead o
P calls lls F1.
I/O
Ad Adap aptor r does not t re retu turn rn to to p, s sched eduling
er t threa eads. s. The a adaptor calls P finally
I/O complete
20
– There is a combination that uses both of them: Cooperative Task Management with automatic stack management
– Interactions between ASM and MSM – Adaptor can solve this problem by connecting each of them in the middle.