cooperative task management without manual stack management or, event-driven programming is not the...

22
Cooperative Task Management without Manual Stack Management or, Event-driven Programming is Not the Opposite of Threaded Programming Presented by Li Lei Atul Adya, Jon Howell, Marvin Theimer, William J. Bolosky, John R. Douceur Microsoft Research

Upload: felice

Post on 26-Feb-2016

33 views

Category:

Documents


1 download

DESCRIPTION

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 Lei. Agenda. Introduction - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Cooperative Task Management without Manual Stack Management or, Event-driven Programming is Not the Opposite of Threaded Programming

Cooperative Task Management without Manual Stack Management

or, Event-driven Programming is Not the Opposite of Threaded Programming

Presented by Li Lei

Atul Adya, Jon Howell, Marvin Theimer, William J. Bolosky, John R. Douceur

Microsoft Research

Page 2: Cooperative Task Management without Manual Stack Management or, Event-driven Programming is Not the Opposite of Threaded Programming

Agenda

1. Introduction2. Task Management and Stack Management3. A Hybrid Approach4. Conclusion

2

Page 3: Cooperative Task Management without Manual Stack Management or, Event-driven Programming is Not the Opposite of Threaded Programming

Introduction

• Motivation– People think “event-driven” programming is the opposite of

“multithreaded” programming.– Combination of these two styles has some problems.

• Solution– We can combine these two styles, with concerning two issues.– Provide an approach to solving these problems.

Page 4: Cooperative Task Management without Manual Stack Management or, Event-driven Programming is Not the Opposite of Threaded Programming

Agenda

1. Introduction2. Task Management and Stack Management3. A Hybrid Approach4. Conclusion

4

Page 5: Cooperative Task Management without Manual Stack Management or, Event-driven Programming is Not the Opposite of Threaded Programming

Task Management• Preemptive Task Management

– Execution of tasks can interleave on uniprocessor or overlap on multiprocessor

– Efficient but has race conditions• Serial Task Management

– Executes tasks without any interleavings– No race condition but inefficient, e.g blocking on I/O

• Cooperative Task Management– 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

Page 6: Cooperative Task Management without Manual Stack Management or, Event-driven Programming is Not the Opposite of Threaded Programming

A

B

B

A

A

A

B

A

B

A

I/O

I/O complete

Preemptive Serial Cooperative

Page 7: Cooperative Task Management without Manual Stack Management or, Event-driven Programming is Not the Opposite of Threaded Programming

Stack Management

• Automatic Stack Management (ASM)– With ASM, the programmer expresses each complete task as a

single procedure in the source language– It is associated with the style “multithreaded” programming

• Manual Stack Management (MSM)– 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

Page 8: Cooperative Task Management without Manual Stack Management or, Event-driven Programming is Not the Opposite of Threaded Programming

ASM vs. MSM

P()

I/O

I/O completesI/O

A procedure p with ASMA procedure P with its two event handlers P1, P2, by MSM

P1()

P2()

Page 9: Cooperative Task Management without Manual Stack Management or, Event-driven Programming is Not the Opposite of Threaded Programming

Based on these issues, we clarify … St

ack

Man

agem

ent

Task Management

Cooperative Preemptive

Man

ual

Auto

mati

c

Event-driven

MultithreadedSweet spot

Not Oppossit

e

Page 10: Cooperative Task Management without Manual Stack Management or, Event-driven Programming is Not the Opposite of Threaded Programming

Disadvantages of MSM and ASM

• Disadvantages of MSM– Affect on program structures– Introduce more rules about semantics– Software evolution exacerbates this problem

• Disadvantages of ASM– Callee procedure as yielding affects the property of caller procedure– Software evolution bring such a problem

Page 11: Cooperative Task Management without Manual Stack Management or, Event-driven Programming is Not the Opposite of Threaded Programming

Agenda

1. Introduction2. Task Management and Stack Management3. A Hybrid Approach4. Conclusion

11

Page 12: Cooperative Task Management without Manual Stack Management or, Event-driven Programming is Not the Opposite of Threaded Programming

A Hybrid Approach…

• Combination of ASM and MSM– Combines their advantages and avoid their disadvantages– In software development, programmers working on a same

project can use what ever styles they like

• Some problems exist in the hybrid approach– The code with MSM calls the code with ASM (MSM calls ASM)– The code with ASM calls the code with MSM (ASM calls MSM)

Page 13: Cooperative Task Management without Manual Stack Management or, Event-driven Programming is Not the Opposite of Threaded Programming

MSM calls ASM Problem 1

P1

F()

I/O

F()

P2

• P is a procedure with MSM, including two event handler P1, and P2.• F is a procedure with ASM, including I/O operations.• P1 calls F, and P2 is invoked when F finishes• They are running at a single thread

Both P and F block on I/O !

Page 14: Cooperative Task Management without Manual Stack Management or, Event-driven Programming is Not the Opposite of Threaded Programming

ASM calls MSM Problem 2

P

F1

F2

P

• P is a procedure with ASM• F is a procedure with MSM, and two event handlers, including I/O operations,• P calls F1, and F2 is invoked when I/o completes

P

Immediately Return to P once F1 finishes

Second return to P after F2 finishes I/O completion .

I/OI/O

Completetion

Page 15: Cooperative Task Management without Manual Stack Management or, Event-driven Programming is Not the Opposite of Threaded Programming

How to solve these problems?

Use some glue code that can connect them smoothly …

The approach in the paper uses an adaptor to insert between the code with ASM and the code with MSM such that the codes with different styles can not directly communicate.

Code with ASM Code with MSM

Adap

tor

Page 16: Cooperative Task Management without Manual Stack Management or, Event-driven Programming is Not the Opposite of Threaded Programming

MSM calls ASM Problem 1

P1

F()

I/O

F()

P2

• P is a procedure with MSM, including two event handler P1, and P2.• F is a procedure with ASM, including I/O operations.• P1 calls F, and P2 is invoked when F finishes• They are running at a single thread

Page 17: Cooperative Task Management without Manual Stack Management or, Event-driven Programming is Not the Opposite of Threaded Programming

MSM calls ASMP1

F()

I/O

F()

P2

Adaptor

Adaptor

P1

Adaptor fork a new thread and execute F on it.

The control can be schedule back.

F calls back adptor, with P2, handler.

Page 18: Cooperative Task Management without Manual Stack Management or, Event-driven Programming is Not the Opposite of Threaded Programming

ASM calls MSM Problem 2

P

F1

F2

P

• P is a procedure with ASM• F is a procedure with MSM, and two event handlers, including I/O operations,• P calls F1, and F2 is invoked when I/o completes

P I/OI/O

Completetion

Page 19: Cooperative Task Management without Manual Stack Management or, Event-driven Programming is Not the Opposite of Threaded Programming

ASM calls MSMP

F1

F2

P

Adaptor

Adaptor

I/O

Adaptor

Adaptor calls F1 instead of P calls F1.

I/O Adaptor does not return to p, scheduling other threads.

The adaptor calls P finally

I/O complete

Page 20: Cooperative Task Management without Manual Stack Management or, Event-driven Programming is Not the Opposite of Threaded Programming

Agenda

1. Introduction2. Task Management and Stack Management3. A Hybrid Approach4. Conclusion

20

Page 21: Cooperative Task Management without Manual Stack Management or, Event-driven Programming is Not the Opposite of Threaded Programming

Conclusion

• “Event-driven” is not the opposite of “multithreaded”– There is a combination that uses both of them: Cooperative Task

Management with automatic stack management

• Some problems are addressed in combination– Interactions between ASM and MSM– Adaptor can solve this problem by connecting each of them in

the middle.

Page 22: Cooperative Task Management without Manual Stack Management or, Event-driven Programming is Not the Opposite of Threaded Programming

QUESTIONS ?