| 1 | # Copyright (C) 2010, Parrot Foundation. |
|---|
| 2 | # $Id$ |
|---|
| 3 | |
|---|
| 4 | =head1 PDD 30: Threads |
|---|
| 5 | |
|---|
| 6 | =head2 Abstract |
|---|
| 7 | |
|---|
| 8 | This PDD outlines Parrot's design roadmap for parallelism support |
|---|
| 9 | |
|---|
| 10 | =head2 Version |
|---|
| 11 | |
|---|
| 12 | $Revision$ |
|---|
| 13 | |
|---|
| 14 | =head2 Synopsis |
|---|
| 15 | |
|---|
| 16 | =item Low level Parrot Threads |
|---|
| 17 | |
|---|
| 18 | ParrotThread PMC will be the interface to a OS schedulable entity. |
|---|
| 19 | ThreadInterpreter PMC will be the actual object that represents a OS schedulable entity. |
|---|
| 20 | The shared of the heap, subs, arguments, and globals with the parent Interpreter will be configurable |
|---|
| 21 | with flags. |
|---|
| 22 | |
|---|
| 23 | ParrotThread is expected to be a low level abstraction of an OS schedulable entity, over which more user |
|---|
| 24 | friendly parallelism constructs and pmcs can be created. |
|---|
| 25 | |
|---|
| 26 | Because of the degree of sharing between a ParrotThread and its parent is parameterizable, it is expected that |
|---|
| 27 | direct instanciation of ParrotThreads will generally be restricted from the VM user for security and safety reasons. |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | =item High level Parallelism PMCs |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | Place PMC extends ParrotThread and will be a message passing ONLY interface to a OS schedulable entity. |
|---|
| 34 | PlaceInterpreter extens ThreadInterpreter PMC. |
|---|
| 35 | |
|---|
| 36 | Future PMC extends ParrotThread and will be a fork/join, safe shared memory access to a OS schedulable entity. |
|---|
| 37 | FutureInterpreter extends ThreadInterpreter PMC. |
|---|
| 38 | |
|---|
| 39 | Futures provide safe access (via a restricted runloop) to shared memory by greatly restricting the operations a future can perform. |
|---|
| 40 | Futures typically only execute arithmetic and function call ops, and only access fixed size containers. |
|---|
| 41 | When a future attempts to execute a unsafe operation the computation is suspended and executed by the parent interpreter when it "touches" |
|---|
| 42 | or joins on the spawned future. |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | =item Unsafe OS Threads |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | While the author recommends against the use of general purpose shared memory threads in Parrot, |
|---|
| 49 | a UnsafeParrotThread PMC can be created that exposes Parrot mutexes, semaphores, condition variables, barriers, to the |
|---|
| 50 | fearless end user programers. |
|---|
| 51 | |
|---|
| 52 | Shared memory threads in a language runtime make ensuring safety(the VM wont crash) essentially impossible. |
|---|
| 53 | For security and stability reasons I envision UnsafeParrotThread disabled by most users. |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | =item Green Threads |
|---|
| 57 | |
|---|
| 58 | GreenThreadPMC will be the interface to a User schedulable entity. |
|---|
| 59 | GreenThreadInterpreter PMC extends Interpreter will be the actual container of the execution state of the Green Thread. |
|---|
| 60 | |
|---|
| 61 | GreenThreads will be scheduled by the concurrency scheduler allowing intra OS schedulable entity concurrency. |
|---|
| 62 | beginAtomic and endAtomic methods (with a recursive call counter) on GreenThreads will prevent a green thread from being descheduled until end |
|---|
| 63 | atomic is called for each beginAtomic. |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | =item Process level Parallelism. |
|---|
| 68 | |
|---|
| 69 | ForkedProcessPMC will be the interface to a forked process. |
|---|
| 70 | ExecedProcessPMC extends ForkedProcessPMC and will be the interface to fork execed processes. |
|---|
| 71 | |
|---|
| 72 | =item GC Support. |
|---|
| 73 | |
|---|
| 74 | When a GC needs to occur, a global flag will be set. |
|---|
| 75 | OS Schedulable threads will rendezvous at at barrier via the concurrency schedular interrupt mechanism. |
|---|
| 76 | Once all the OS Schedule threads have rendezvous (stop the world) collection can occur. |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | =item Google Summer of Code 2010 Project. |
|---|
| 80 | |
|---|
| 81 | Worker Thread Pool PMCs should be easily build on top of ParrotThread PMCs. |
|---|
| 82 | Note: Scheduling tasks(Parrot subs) to OS Schedulable threads allows for unsafe behavior that can arbitarily |
|---|
| 83 | crash the Parrot VM. |
|---|
| 84 | |
|---|
| 85 | =over |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | =head2 Dependencies |
|---|
| 89 | |
|---|
| 90 | =head2 Definitions |
|---|
| 91 | |
|---|
| 92 | =head2 Implementation |
|---|
| 93 | |
|---|
| 94 | =head2 Attachments |
|---|
| 95 | |
|---|
| 96 | None. |
|---|
| 97 | |
|---|
| 98 | =head2 Footnotes |
|---|
| 99 | |
|---|
| 100 | None. |
|---|
| 101 | |
|---|
| 102 | =head2 References |
|---|
| 103 | |
|---|
| 104 | The design has been liberally taken from PLT Scheme which implements all of the above constructs. |
|---|
| 105 | |
|---|
| 106 | None. |
|---|
| 107 | |
|---|
| 108 | =cut |
|---|
| 109 | |
|---|
| 110 | __END__ |
|---|
| 111 | Local Variables: |
|---|
| 112 | fill-column:78 |
|---|
| 113 | End: |
|---|