Presentation is loading. Please wait.

Presentation is loading. Please wait.

Cooperative Task Management without Manual Stack management Hanyun Tao EECS 582 – W161.

Similar presentations


Presentation on theme: "Cooperative Task Management without Manual Stack management Hanyun Tao EECS 582 – W161."— Presentation transcript:

1 Cooperative Task Management without Manual Stack management Hanyun Tao EECS 582 – W161

2 The War of Programming Model Event Driven v.s Multithreaded Berkeley: Stanford: EECS 582 – W162

3 Event Driven Programming Model Easy to use when reasoning about concurrency Code difficult to read Code difficult to maintain Good for single-processor (cooperative concurrency) EECS 582 – W163

4 Multithreaded Programming Model Code is more readable Code is easier to maintain Difficult to reason about concurrency with threads Good for multi-processors (true concurrency) EECS 582 – W164

5 Goal : Get the Best from both World! EECS 582 – W165

6 Definition of Terms  Task Management  Stack Management  I/O Management  Conflict Management  Data Partitioning EECS 582 – W166

7 Task Management Preemptive Task Management Tasks can interleave on uniprocessor or overlap on multiprocessor Serial Task Management One at a time, no conflict Cooperative Task Management Only yields control to other tasks at a well-defined point Such as wait for long-running I/O EECS 582 – W167

8 Stack Management Manual Stack Management Inherent in Cooperative Task Management Finishing a “single” tasks may require to rip stack for multiple time Automatic Stack Management Inherent in pre-emptive Task Management Downside: Hidden concurrency assumptions Solution: Static & Dynamic Check EECS 582 – W168

9 Other Management Models I/O Management Asynchronous versus Synchronous I/O Management Conflict Management Concerned with avoiding resource conflicts Serial & Cooperative (between yield point) – Atomic, no need to avoid conflict Preemptive Task Management – need synchronization primitives Data Partitioning The more you break up your shared state, the fewer conflicts you should have EECS 582 – W169

10 The Sweet Spot EECS 582 – W1610 Cooperative tasks are the most desirable when reasoning about concurrency usually associated with event-driven programming Automatic stack management is the most desirable when reading/maintaining code Usually associated with threaded or serial programming

11 The Sweet Spot EECS 582 – W1611

12 Solution Build a system that uses Cooperative Task Management without Manual Stack Management Pulls together the best of both worlds Ease of reasoning about concurrency Readable/maintainable code EECS 582 – W1612

13 Implementation Detail Use fibers User level thread package Many-to-many threading solution for Windows Platform Non-preemptive Scheduled cooperatively – one fiber hands control off to another fiber Scheduling multiple fiber on a single thread EECS 582 – W1613

14 Implementation Detail A Scheduler runs on a MainFiber Schedule both manual stack management code and automatic stack management code Code written with manual stack management always runs on a fiber other than MainFiber Compute-Only functions can run on any fiber EECS 582 – W1614

15 Manual Calling Automatic Uses a Continuation to Fiber Adapter (CFA): Glues the notion of a continuation to the notion of a blocking call Handles the details of the continuation: rips itself into two, schedules the second half within the first and calls the blocking function on the second fiber Second half of CFA uses continuation to call the original task’s continuation EECS 582 – W1615

16 Manual Calling Automatic EECS 582 – W1616

17 Automatic Calling Manual Uses a Fiber to Continuation Adapter (FCA) FCA executes on secondary thread May short-circuit if no blocking occurred Glues the notion of a blocking call to one that uses a continuation Handles the details of the transformation: creates a new “fiberContinuation” which causes MainFiber to switch back to the secondary fiber, executes the manual stack function and switches back to the main thread FiberContinuation simply resumes the suspended fiber EECS 582 – W1617

18 Automatic Calling Manual EECS 582 – W1618

19 Conclusion Clarify the Debate of Event Driven & Multithreaded Model by Identifying two separate Concepts Task Management Stack Management Presents a hybrid model that adapts between code with automatic and with manual stack management Enabling cooperation among disparate programmers & code bases EECS 582 – W1619


Download ppt "Cooperative Task Management without Manual Stack management Hanyun Tao EECS 582 – W161."

Similar presentations


Ads by Google