- File:
-
- 1 edited
-
doc/papers/concurrency/Paper.tex (modified) (39 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/concurrency/Paper.tex
r4487667 rbd12159 311 311 Libraries like pthreads were developed for C, and the Solaris operating-system switched from user (JDK 1.1~\cite{JDK1.1}) to kernel threads. 312 312 As a result, languages like Java, Scala, Objective-C~\cite{obj-c-book}, \CCeleven~\cite{C11}, and C\#~\cite{Csharp} adopt the 1:1 kernel-threading model, with a variety of presentation mechanisms. 313 From 2000 onwards, languages like Go~\cite{Go}, Erlang~\cite{Erlang}, Haskell~\cite{Haskell}, D~\cite{D}, and \uC~\cite{uC++,uC++book} have championed the M:N user-threading model, and many user-threading libraries have appeared~\cite{Qthreads,MPC, Marcel}, including putting green threads back into Java~\cite{Quasar}.313 From 2000 onwards, languages like Go~\cite{Go}, Erlang~\cite{Erlang}, Haskell~\cite{Haskell}, D~\cite{D}, and \uC~\cite{uC++,uC++book} have championed the M:N user-threading model, and many user-threading libraries have appeared~\cite{Qthreads,MPC,BoostThreads}, including putting green threads back into Java~\cite{Quasar}. 314 314 The main argument for user-level threading is that they are lighter weight than kernel threads (locking and context switching do not cross the kernel boundary), so there is less restriction on programming styles that encourage large numbers of threads performing medium work-units to facilitate load balancing by the runtime~\cite{Verch12}. 315 315 As well, user-threading facilitates a simpler concurrency approach using thread objects that leverage sequential patterns versus events with call-backs~\cite{vonBehren03}. … … 327 327 328 328 Finally, it is important for a language to provide safety over performance \emph{as the default}, allowing careful reduction of safety for performance when necessary. 329 Two concurrency violations of this philosophy are \emph{spurious wakeup} (random wakeup~\cite[\S~8]{Buhr05a}) and \emph{barging} (signals-as-hints~\cite[\S~8]{Buhr05a}), where one is a consequence of the other, i.e., once there is spurious wakeup, signals-as-hints follows.329 Two concurrency violations of this philosophy are \emph{spurious wakeup} and \emph{barging}, i.e., random wakeup~\cite[\S~8]{Buhr05a} and signals-as-hints~\cite[\S~8]{Buhr05a}, where one is a consequence of the other, i.e., once there is spurious wakeup, signals-as-hints follows. 330 330 However, spurious wakeup is \emph{not} a foundational concurrency property~\cite[\S~8]{Buhr05a}, it is a performance design choice. 331 331 Similarly, signals-as-hints is often a performance decision. 332 332 We argue removing spurious wakeup and signals-as-hints makes concurrent programming significantly safer because it removes local non-determinism and matches with programmer expectation. 333 (Author experience teaching concurrency is that students are highly confused by these semantics.)333 (Authors experience teaching concurrency is that students are highly confused by these semantics.) 334 334 Clawing back performance, when local non-determinism is unimportant, should be an option not the default. 335 335 … … 367 367 \section{Stateful Function} 368 368 369 The stateful function is an old idea~\cite{Conway63,Marlin80} that is new again~\cite{C++20Coroutine19}, where execution is temporarily suspended and later resumed, e.g., plugin, device driver, finite-state machine. 369 The generator/coroutine provides a stateful function, which is an old idea~\cite{Conway63,Marlin80} that is new again~\cite{C++20Coroutine19}. 370 A stateful function allows execution to be temporarily suspended and later resumed, e.g., plugin, device driver, finite-state machine. 370 371 Hence, a stateful function may not end when it returns to its caller, allowing it to be restarted with the data and execution location present at the point of suspension. 371 372 This capability is accomplished by retaining a data/execution \emph{closure} between invocations. … … 542 543 \end{figure} 543 544 544 Stateful functions appear as generators, coroutines, and threads, where presentations are based on function objects or pointers~\cite{Butenhof97, C++14, MS:VisualC++, BoostCoroutines15}.545 For generators, coroutines, and threads, many designs are based on function objects or pointers~\cite{Butenhof97, C++14, MS:VisualC++, BoostCoroutines15}. 545 546 For example, Python presents generators as a function object: 546 547 \begin{python} … … 586 587 587 588 Figure~\ref{f:FibonacciAsymmetricGenerator} shows an unbounded asymmetric generator for an infinite sequence of Fibonacci numbers written in C and \CFA, with a simple C implementation for the \CFA version. 588 This generator is an \emph{output generator}, producing a new result on each resumption.589 This kind of generator is an \emph{output generator}, producing a new result on each resumption. 589 590 To compute Fibonacci, the previous two values in the sequence are retained to generate the next value, \ie @fn1@ and @fn@, plus the execution location where control restarts when the generator is resumed, \ie top or middle. 590 An additional requirement is the ability to create an arbitrary number of generators (of any kind), \ie retaining onestate in global variables is insufficient;591 An additional requirement is the ability to create an arbitrary number of generators (of any kind), \ie retaining state in global variables is insufficient; 591 592 hence, state is retained in a closure between calls. 592 593 Figure~\ref{f:CFibonacci} shows the C approach of manually creating the closure in structure @Fib@, and multiple instances of this closure provide multiple Fibonacci generators. 593 The C version only has the middle execution state because the top execution state is declaration initialization.594 The C version only has the middle execution state because the top execution state becomes declaration initialization. 594 595 Figure~\ref{f:CFAFibonacciGen} shows the \CFA approach, which also has a manual closure, but replaces the structure with a custom \CFA @generator@ type. 595 596 This generator type is then connected to a function that \emph{must be named \lstinline|main|},\footnote{ … … 667 668 As well, the data state is small, where variables @byte@ and @msg@ are communication variables for passing in message bytes and returning the message, and variables @lnth@, @crc@, and @sum@ are local variable that must be retained between calls and are manually hoisted into the generator type. 668 669 % Manually, detecting and hoisting local-state variables is easy when the number is small. 669 In contrast, the execution state is large, with one @resume@ and seven @suspend@s.670 Finally, the execution state is large, with one @resume@ and seven @suspend@s. 670 671 Hence, the key benefits of the generator are correctness, safety, and maintenance because the execution states are transcribed directly into the programming language rather than using a table-driven approach. 671 672 Because FSMs can be complex and occur frequently in important domains, direct support of the generator is crucial in a systems programming-language. … … 779 780 Figure~\ref{f:CFAPingPongGen} shows a symmetric generator, where the generator resumes another generator, forming a resume/resume cycle. 780 781 (The trivial cycle is a generator resuming itself.) 781 This control flow is similar to recursion for functions but without stack growth.782 This control flow is similar to recursion for functions, but without stack growth. 782 783 The steps for symmetric control-flow are creating, executing, and terminating the cycle. 783 784 Constructing the cycle must deal with definition-before-use to close the cycle, \ie, the first generator must know about the last generator, which is not within scope. … … 788 789 Terminating the cycle is accomplished by @suspend@ or @return@, both of which go back to the stack frame that started the cycle (program main in the example). 789 790 The starting stack-frame is below the last active generator because the resume/resume cycle does not grow the stack. 790 Also, since local variables are not retained in the generator function, it does not contain an yobjects with destructors that must be called, so the cost is the same as a function return.791 Also, since local variables are not retained in the generator function, it does not contain an objects with destructors that must be called, so the cost is the same as a function return. 791 792 Destructor cost occurs when the generator instance is deallocated, which is easily controlled by the programmer. 792 793 … … 1219 1220 Hence, the starter coroutine is remembered on the first resume and ending the coroutine resumes the starter. 1220 1221 Figure~\ref{f:ProdConsRuntimeStacks} shows this semantic by the dashed lines from the end of the coroutine mains: @prod@ starts @cons@ so @cons@ resumes @prod@ at the end, and the program main starts @prod@ so @prod@ resumes the program main at the end. 1221 For other scenarios, it is always possible to devise a solution with additional programming effort , such as forcing the cycle forward (backward) to a safe point before starting termination.1222 For other scenarios, it is always possible to devise a solution with additional programming effort. 1222 1223 1223 1224 The producer/consumer example does not illustrate the full power of the starter semantics because @cons@ always ends first. … … 1289 1290 The function definitions ensures there is a statically-typed @main@ function that is the starting point (first stack frame) of a coroutine, and a mechanism to get (read) the currently executing coroutine handle. 1290 1291 The @main@ function has no return value or additional parameters because the coroutine type allows an arbitrary number of interface functions with corresponding arbitrary typed input/output values versus fixed ones. 1291 The advantage of this approach is that users can easily create different types of coroutines, \eg changing the memory layout of a coroutine is trivial when implementing the @get_coroutine@ function, and possibly redefining \textsf{suspend}and @resume@.1292 The advantage of this approach is that users can easily create different types of coroutines, \eg changing the memory layout of a coroutine is trivial when implementing the @get_coroutine@ function, and possibly redefining @suspend@ and @resume@. 1292 1293 1293 1294 The \CFA custom-type @coroutine@ implicitly implements the getter and forward declarations for the coroutine main. … … 1337 1338 Once allocated, a VLS is fixed sized.} 1338 1339 on the allocating stack, provided the allocating stack is large enough. 1339 For a VLS stack allocation /deallocation is an inexpensive adjustment of the stack pointer, modulo any stack constructor costs (\eg initial frame setup).1340 For a VLS stack allocation, allocation/deallocation is an inexpensive adjustment of the stack point, modulo any stack constructor costs (\eg initial frame setup). 1340 1341 For heap stack allocation, allocation/deallocation is an expensive heap allocation (where the heap can be a shared resource), modulo any stack constructor costs. 1341 1342 With heap stack allocation, it is also possible to use a split (segmented) stack calling-convention, available with gcc and clang, so the stack is variable sized. … … 1362 1363 However, coroutines are a stepping stone towards concurrency. 1363 1364 1364 The transition to concurrency, even for a single thread with multiple stacks, occurs when coroutines context switch to a \newterm{scheduling coroutine}, introducing non-determinism from the coroutine perspective~\cite[\S~3,]{Buhr05a} .1365 The transition to concurrency, even for a single thread with multiple stacks, occurs when coroutines context switch to a \newterm{scheduling coroutine}, introducing non-determinism from the coroutine perspective~\cite[\S~3,]{Buhr05a}\cite{Adya02}. 1365 1366 Therefore, a minimal concurrency system requires coroutines \emph{in conjunction with a nondeterministic scheduler}. 1366 The resulting execution system now follows a cooperative threading-model ~\cite{Adya02,libdill}, called \newterm{non-preemptive scheduling}.1367 The resulting execution system now follows a cooperative threading-model, called \newterm{non-preemptive scheduling}. 1367 1368 Adding \newterm{preemption} introduces non-cooperative scheduling, where context switching occurs randomly between any two instructions often based on a timer interrupt, called \newterm{preemptive scheduling}. 1368 1369 While a scheduler introduces uncertain execution among explicit context switches, preemption introduces uncertainty by introducing implicit context switches. … … 1423 1424 This semantic ensures a thread is started and stopped exactly once, eliminating some programming error, and scales to multiple threads for basic (termination) synchronization. 1424 1425 For block allocation to arbitrary depth, including recursion, threads are created/destroyed in a lattice structure (tree with top and bottom). 1425 Arbitrary topologies are possible using dynamic allocation, allowing threads to outlive their declaration scope, identical to normal dynamic allocation.1426 Arbitrary topologies are possible using dynamic allocation, allowing threads to outlive their declaration scope, identical to normal dynamically allocating. 1426 1427 \begin{cfa} 1427 1428 MyTask * factory( int N ) { ... return `anew( N )`; } $\C{// allocate heap-based threads, implicit start after construction}$ … … 1524 1525 \subsection{Mutual Exclusion} 1525 1526 1526 A group of instructions manipulating a specific instance of shared data that must be performed atomically is called a \newterm{critical section}~\cite{Dijkstra65}, which is enforced by \newterm{simple mutual-exclusion}.1527 The generalization is called a \newterm{group critical-section}~\cite{Joung00}, where multiple tasks with the same session use the resource simultaneously and different sessions are segregated, which is enforced by \newterm{complex mutual-exclusion} providing the correct kind and number of threads using a group critical-section.1527 A group of instructions manipulating a specific instance of shared data that must be performed atomically is called an (individual) \newterm{critical-section}~\cite{Dijkstra65}. 1528 The generalization is called a \newterm{group critical-section}~\cite{Joung00}, where multiple tasks with the same session may use the resource simultaneously, but different sessions may not use the resource simultaneously. 1528 1529 The readers/writer problem~\cite{Courtois71} is an instance of a group critical-section, where readers share a session but writers have a unique session. 1530 \newterm{Mutual exclusion} enforces the correct kind and number of threads using a critical section. 1529 1531 1530 1532 However, many solutions exist for mutual exclusion, which vary in terms of performance, flexibility and ease of use. … … 1546 1548 Preventing or detecting barging is an involved challenge with low-level locks, which is made easier through higher-level constructs. 1547 1549 This challenge is often split into two different approaches: barging avoidance and prevention. 1548 Algorithms that unconditionally releasing a lock for competing threads to acquire use barging avoidance during synchronization to force a barging thread to wait ;1550 Algorithms that unconditionally releasing a lock for competing threads to acquire use barging avoidance during synchronization to force a barging thread to wait. 1549 1551 algorithms that conditionally hold locks during synchronization, \eg baton-passing~\cite{Andrews89}, prevent barging completely. 1550 1552 … … 1636 1638 For this reason, \CFA requires programmers to identify the kind of parameter with the @mutex@ keyword and uses no keyword to mean \lstinline[morekeywords=nomutex]@nomutex@. 1637 1639 1640 \newpage 1638 1641 The next semantic decision is establishing which parameter \emph{types} may be qualified with @mutex@. 1639 1642 The following has monitor parameter types that are composed of multiple objects. … … 1734 1737 1735 1738 Users can still force the acquiring order by using @mutex@/\lstinline[morekeywords=nomutex]@nomutex@. 1739 \newpage 1736 1740 \begin{cfa} 1737 1741 void foo( M & mutex m1, M & mutex m2 ); $\C{// acquire m1 and m2}$ … … 1744 1748 \end{cfa} 1745 1749 The bulk-acquire semantics allow @bar@ or @baz@ to acquire a monitor lock and reacquire it in @foo@. 1746 The calls to @bar@ and @baz@ acquired the monitorsin opposite order, possibly resulting in deadlock.1750 In the calls to @bar@ and @baz@, the monitors are acquired in opposite order, possibly resulting in deadlock. 1747 1751 However, this case is the simplest instance of the \emph{nested-monitor problem}~\cite{Lister77}, where monitors are acquired in sequence versus bulk. 1748 1752 Detecting the nested-monitor problem requires dynamic tracking of monitor calls, and dealing with it requires rollback semantics~\cite{Dice10}. … … 1795 1799 % It is only in this way that a waiting program has an absolute guarantee that it can acquire the resource just released by the signalling program without any danger that a third program will interpose a monitor entry and seize the resource instead.~\cite[p.~550]{Hoare74} 1796 1800 % \end{cquote} 1797 Furthermore, \CFA concurrency has no spurious wakeup~\cite[\S~9]{Buhr05a}, which eliminates an implicit form of selfbarging.1801 Furthermore, \CFA concurrency has no spurious wakeup~\cite[\S~9]{Buhr05a}, which eliminates an implicit form of barging. 1798 1802 Hence, a \CFA @wait@ statement is not enclosed in a @while@ loop retesting a blocking predicate, which can cause thread starvation due to barging. 1799 1803 1800 Figure~\ref{f:MonitorScheduling} shows generalinternal/external scheduling (for the bounded-buffer example in Figure~\ref{f:InternalExternalScheduling}).1804 Figure~\ref{f:MonitorScheduling} shows internal/external scheduling (for the bounded-buffer example in Figure~\ref{f:InternalExternalScheduling}). 1801 1805 External calling threads block on the calling queue, if the monitor is occupied, otherwise they enter in FIFO order. 1802 Internal threads block on condition queues via @wait@ and they reenter from the condition in FIFO order , or they block on urgent via @signal_block@ or @waitfor@ and reenter implicit when the monitor becomes empty, \ie, the thread in the monitor exits or waits.1806 Internal threads block on condition queues via @wait@ and they reenter from the condition in FIFO order. 1803 1807 1804 1808 There are three signalling mechanisms to unblock waiting threads to enter the monitor. 1805 Note, signalling cannot have the signaller and signalled thread in the monitor simultaneously because of the mutual exclusion so only onecan proceed.1809 Note, signalling cannot have the signaller and signalled thread in the monitor simultaneously because of the mutual exclusion so only can proceed. 1806 1810 For internal scheduling, threads are unblocked from condition queues using @signal@, where the signallee is moved to urgent and the signaller continues (solid line). 1807 1811 Multiple signals move multiple signallees to urgent, until the condition is empty. … … 1816 1820 Executing multiple @waitfor@s from different signalled functions causes the calling threads to move to urgent. 1817 1821 External scheduling requires urgent to be a stack, because the signaller excepts to execute immediately after the specified monitor call has exited or waited. 1818 Internal scheduling behaves the same for an urgent stack or queue, except for multiple signalling, where the threads unblock from urgent in reverse order from signalling. 1819 If the restart order is important, multiple signalling by a signal thread can be transformed into daisy-chain signalling among threads, where each thread signals the next thread. 1820 We tried both a stack for @waitfor@ and queue for signalling, but that resulted in complex semantics about which thread enters next. 1821 Hence, \CFA uses a single urgent stack to correctly handle @waitfor@ and adequately support both forms of signalling. 1822 Internal scheduling behaves the same for an urgent stack or queue, except for signalling multiple threads, where the threads unblock from urgent in reverse order from signalling. 1823 If the restart order is important, multiple signalling by a signal thread can be transformed into shared signalling among threads, where each thread signals the next thread. 1824 Hence, \CFA uses an urgent stack. 1822 1825 1823 1826 \begin{figure} … … 1837 1840 \end{figure} 1838 1841 1839 Figure~\ref{f:BBInt} shows a \CFA generic bounded-buffer with internal scheduling, where producers/consumers enter the monitor, detectthe buffer is full/empty, and block on an appropriate condition variable, @full@/@empty@.1842 Figure~\ref{f:BBInt} shows a \CFA generic bounded-buffer with internal scheduling, where producers/consumers enter the monitor, see the buffer is full/empty, and block on an appropriate condition variable, @full@/@empty@. 1840 1843 The @wait@ function atomically blocks the calling thread and implicitly releases the monitor lock(s) for all monitors in the function's parameter list. 1841 1844 The appropriate condition variable is signalled to unblock an opposite kind of thread after an element is inserted/removed from the buffer. … … 1961 1964 External scheduling is controlled by the @waitfor@ statement, which atomically blocks the calling thread, releases the monitor lock, and restricts the function calls that can next acquire mutual exclusion. 1962 1965 If the buffer is full, only calls to @remove@ can acquire the buffer, and if the buffer is empty, only calls to @insert@ can acquire the buffer. 1963 Calls threads to functions that are currently excluded block outside of (external to) the monitor on the calling queue, versus blocking on condition queues inside of (internal to) the monitor.1966 Threads making calls to functions that are currently excluded block outside of (external to) the monitor on the calling queue, versus blocking on condition queues inside of (internal to) the monitor. 1964 1967 Figure~\ref{f:RWExt} shows a readers/writer lock written using external scheduling, where a waiting reader detects a writer using the resource and restricts further calls until the writer exits by calling @EndWrite@. 1965 1968 The writer does a similar action for each reader or writer using the resource. 1966 1969 Note, no new calls to @StarRead@/@StartWrite@ may occur when waiting for the call to @EndRead@/@EndWrite@. 1967 External scheduling allows waiting for events from other threads while restricting unrelated events , that would otherwise have to wait on conditions in the monitor.1970 External scheduling allows waiting for events from other threads while restricting unrelated events. 1968 1971 The mechnaism can be done in terms of control flow, \eg Ada @accept@ or \uC @_Accept@, or in terms of data, \eg Go @select@ on channels. 1969 1972 While both mechanisms have strengths and weaknesses, this project uses the control-flow mechanism to be consistent with other language features. … … 1980 1983 Furthermore, barging corrupts the dating service during an exchange because a barger may also match and change the phone numbers, invalidating the previous exchange phone number. 1981 1984 Putting loops around the @wait@s does not correct the problem; 1982 the s imple solution must be restructured to account for barging.1985 the solution must be restructured to account for barging. 1983 1986 1984 1987 \begin{figure} … … 2048 2051 the signaller enters the monitor and changes state, detects a waiting threads that can use the state, performs a non-blocking signal on the condition queue for the waiting thread, and exits the monitor to run concurrently. 2049 2052 The waiter unblocks next from the urgent queue, uses/takes the state, and exits the monitor. 2050 Blocking signal is the reverse, where the waiter is providing the cooperation for the signalling thread;2053 Blocking signalling is the reverse, where the waiter is providing the cooperation for the signalling thread; 2051 2054 the signaller enters the monitor, detects a waiting thread providing the necessary state, performs a blocking signal to place it on the urgent queue and unblock the waiter. 2052 2055 The waiter changes state and exits the monitor, and the signaller unblocks next from the urgent queue to use/take the state. … … 2079 2082 While \CC supports bulk locking, @wait@ only accepts a single lock for a condition variable, so bulk locking with condition variables is asymmetric. 2080 2083 Finally, a signaller, 2084 \newpage 2081 2085 \begin{cfa} 2082 2086 void baz( M & mutex m1, M & mutex m2 ) { … … 2084 2088 } 2085 2089 \end{cfa} 2086 must have acquired at least the same locks as the waiting thread signalled from a condition queue to allow the locks to be passed, and hence, prevent barging.2090 must have acquired at least the same locks as the waiting thread signalled from the condition queue. 2087 2091 2088 2092 Similarly, for @waitfor( rtn )@, the default semantics is to atomically block the acceptor and release all acquired mutex parameters, \ie @waitfor( rtn, m1, m2 )@. … … 2117 2121 The \emph{conditional-expression} of a @when@ may call a function, but the function must not block or context switch. 2118 2122 If there are multiple acceptable mutex calls, selection occurs top-to-bottom (prioritized) among the @waitfor@ clauses, whereas some programming languages with similar mechanisms accept nondeterministically for this case, \eg Go \lstinline[morekeywords=select]@select@. 2119 If some accept guards are true and there are no outstanding calls to these members, the acceptor is blocked until a call to one of these members is made.2123 If some accept guards are true and there are no outstanding calls to these members, the acceptor is accept-blocked until a call to one of these members is made. 2120 2124 If there is a @timeout@ clause, it provides an upper bound on waiting. 2121 2125 If all the accept guards are false, the statement does nothing, unless there is a terminating @else@ clause with a true guard, which is executed instead. … … 2160 2164 However, the basic @waitfor@ semantics do not support this functionality, since using an object after its destructor is called is undefined. 2161 2165 Therefore, to make this useful capability work, the semantics for accepting the destructor is the same as @signal@, \ie the call to the destructor is placed on the urgent queue and the acceptor continues execution, which throws an exception to the acceptor and then the caller is unblocked from the urgent queue to deallocate the object. 2162 Accepting the destructor is theidiomatic way to terminate a thread in \CFA.2166 Accepting the destructor is an idiomatic way to terminate a thread in \CFA. 2163 2167 2164 2168 … … 2254 2258 In the object-oriented scenario, the type and all its operators are always present at compilation (even separate compilation), so it is possible to number the operations in a bit mask and use an $O(1)$ compare with a similar bit mask created for the operations specified in a @waitfor@. 2255 2259 2256 However, in \CFA, monitor functions can be statically added/removed in translation units, making a fast subset check difficult.2260 In \CFA, monitor functions can be statically added/removed in translation units, so it is impossible to apply an $O(1)$ approach. 2257 2261 \begin{cfa} 2258 2262 monitor M { ... }; // common type, included in .h file … … 2261 2265 void g( M & mutex m ) { waitfor( `f`, m ); } 2262 2266 translation unit 2 2263 void `f`( M & mutex m ); $\C{// replacing f and g for type M in this translation unit}$2267 void `f`( M & mutex m ); 2264 2268 void `g`( M & mutex m ); 2265 void h( M & mutex m ) { waitfor( `f`, m ) or waitfor( `g`, m ); } $\C{// extending type M in this translation unit}$2269 void h( M & mutex m ) { waitfor( `f`, m ) or waitfor( `g`, m ); } 2266 2270 \end{cfa} 2267 2271 The @waitfor@ statements in each translation unit cannot form a unique bit-mask because the monitor type does not carry that information. 2268 Hence, function pointers are used to identify the functions listed in the @waitfor@ statement, stored in a variable-sized array .2272 Hence, function pointers are used to identify the functions listed in the @waitfor@ statement, stored in a variable-sized array, 2269 2273 Then, the same implementation approach used for the urgent stack is used for the calling queue. 2270 2274 Each caller has a list of monitors acquired, and the @waitfor@ statement performs a (usually short) linear search matching functions in the @waitfor@ list with called functions, and then verifying the associated mutex locks can be transfers. … … 2276 2280 2277 2281 External scheduling, like internal scheduling, becomes significantly more complex for multi-monitor semantics. 2278 Even in the simplest case, new semantics need to be established.2282 Even in the simplest case, new semantics needs to be established. 2279 2283 \begin{cfa} 2280 2284 monitor M { ... }; … … 2508 2512 2509 2513 For completeness and efficiency, \CFA provides a standard set of low-level locks: recursive mutex, condition, semaphore, barrier, \etc, and atomic instructions: @fetchAssign@, @fetchAdd@, @testSet@, @compareSet@, \etc. 2510 Some of these low-level mechanism are used in the \CFA runtime, but we strongly advocate using high-levelmechanisms whenever possible.2514 However, we strongly advocate using high-level concurrency mechanisms whenever possible. 2511 2515 2512 2516 … … 2564 2568 \label{s:RuntimeStructureCluster} 2565 2569 2566 A \newterm{cluster} is a collection of threads and virtual processors (abstract kernel-thread) that execute the (user) threads from its own ready queue (like an OS executing kernel threads).2570 A \newterm{cluster} is a collection of threads and virtual processors (abstract kernel-thread) that execute the threads from its own ready queue (like an OS). 2567 2571 The purpose of a cluster is to control the amount of parallelism that is possible among threads, plus scheduling and other execution defaults. 2568 2572 The default cluster-scheduler is single-queue multi-server, which provides automatic load-balancing of threads on processors. 2569 However, the scheduler is pluggable, supporting alternative schedulers, such as multi-queue multi-server, with work-stealing/sharing across the virtual processors.2573 However, the scheduler is pluggable, supporting alternative schedulers, such as multi-queue multi-server, with work-stealing/sharing. 2570 2574 If several clusters exist, both threads and virtual processors, can be explicitly migrated from one cluster to another. 2571 2575 No automatic load balancing among clusters is performed by \CFA. … … 2580 2584 \label{s:RuntimeStructureProcessor} 2581 2585 2582 A virtual processor is implemented by a kernel thread (\eg UNIX process), which arescheduled for execution on a hardware processor by the underlying operating system.2586 A virtual processor is implemented by a kernel thread (\eg UNIX process), which is subsequently scheduled for execution on a hardware processor by the underlying operating system. 2583 2587 Programs may use more virtual processors than hardware processors. 2584 2588 On a multiprocessor, kernel threads are distributed across the hardware processors resulting in virtual processors executing in parallel. 2585 2589 (It is possible to use affinity to lock a virtual processor onto a particular hardware processor~\cite{affinityLinux, affinityWindows, affinityFreebsd, affinityNetbsd, affinityMacosx}, which is used when caching issues occur or for heterogeneous hardware processors.) 2586 2590 The \CFA runtime attempts to block unused processors and unblock processors as the system load increases; 2587 balancing the workload with processors is difficult because it requires future knowledge, \ie what will the applicaton workload do next.2591 balancing the workload with processors is difficult. 2588 2592 Preemption occurs on virtual processors rather than user threads, via operating-system interrupts. 2589 2593 Thus virtual processors execute user threads, where preemption frequency applies to a virtual processor, so preemption occurs randomly across the executed user threads. … … 2618 2622 \subsection{Preemption} 2619 2623 2620 Nondeterministic preemption provides fairness from long running threads, and forces concurrent programmers to write more robust programs, rather than relying on section of code between cooperative scheduling to be atomic .2624 Nondeterministic preemption provides fairness from long running threads, and forces concurrent programmers to write more robust programs, rather than relying on section of code between cooperative scheduling to be atomic, 2621 2625 A separate reason for not supporting preemption is that it significantly complicates the runtime system. 2622 2626 Preemption is normally handled by setting a count-down timer on each virtual processor. … … 2645 2649 There are two versions of the \CFA runtime kernel: debug and non-debug. 2646 2650 The debugging version has many runtime checks and internal assertions, \eg stack (non-writable) guard page, and checks for stack overflow whenever context switches occur among coroutines and threads, which catches most stack overflows. 2647 After a program is debugged, the non-debugging version can be used to significantlydecrease space and increase performance.2651 After a program is debugged, the non-debugging version can be used to decrease space and increase performance. 2648 2652 2649 2653 … … 2704 2708 The only note here is that the call stacks of \CFA coroutines are lazily created, therefore without priming the coroutine to force stack creation, the creation cost is artificially low. 2705 2709 2710 \newpage 2706 2711 \begin{multicols}{2} 2707 2712 \lstset{language=CFA,moredelim=**[is][\color{red}]{@}{@},deletedelim=**[is][]{`}{`}} … … 2954 2959 One solution is to offer various tuning options, allowing the scheduler to be adjusted to the requirements of the workload. 2955 2960 However, to be truly flexible, a pluggable scheduler is necessary. 2956 Currently, the \CFA pluggable scheduler is too simple to handle complex scheduling, \eg quality of service and real-time, where the scheduler must interact with mutex objects to deal with issues like priority inversion ~\cite{Buhr00b}.2961 Currently, the \CFA pluggable scheduler is too simple to handle complex scheduling, \eg quality of service and real-time, where the scheduler must interact with mutex objects to deal with issues like priority inversion. 2957 2962 2958 2963 \paragraph{Non-Blocking I/O} … … 2987 2992 \section{Acknowledgements} 2988 2993 2989 The authors would like to recognize the design assistance of Aaron Moss, Rob Schluntz , Andrew Beach and Michael Brookson the features described in this paper.2994 The authors would like to recognize the design assistance of Aaron Moss, Rob Schluntz and Andrew Beach on the features described in this paper. 2990 2995 Funding for this project has been provided by Huawei Ltd.\ (\url{http://www.huawei.com}). %, and Peter Buhr is partially funded by the Natural Sciences and Engineering Research Council of Canada. 2991 2996
Note:
See TracChangeset
for help on using the changeset viewer.