You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lkmpg.tex
+9-6Lines changed: 9 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -1645,16 +1645,19 @@ \subsection{Completions}
1645
1645
Sometimes one thing should happen before another within a module having multiple threads.
1646
1646
Rather than using \sh|/bin/sleep| commands, the kernel has another way to do this which allows timeouts or interrupts to also happen.
1647
1647
1648
-
In the following example two threads are started, but one needs to start before another.
1648
+
Completions as code synchronization mechanism have three main parts, initialization of struct completion synchronization object, the waiting or barrier part through \cpp|wait_for_completion()|, and the signalling side through a call to \cpp|complete()|.
1649
1649
1650
-
\samplec{examples/completions.c}
1651
-
1652
-
The \cpp|machine| structure stores the completion states for the two threads.
1650
+
In the subsequent example, two threads are initiated: crank and flywheel.
1651
+
It is imperative that the crank thread starts before the flywheel thread.
1652
+
A completion state is established for each of these threads, with a distinct completion defined for both the crank and flywheel threads.
1653
1653
At the exit point of each thread the respective completion state is updated, and \cpp|wait_for_completion| is used by the flywheel thread to ensure that it does not begin prematurely.
1654
+
The crank thread uses the \cpp|complete_all()| function to update the completion, which lets the flywheel thread continue.
1654
1655
1655
-
So even though \cpp|flywheel_thread| is started first you should notice if you load this module and run \sh|dmesg| that turning the crank always happens first because the flywheel thread waits for it to complete.
1656
+
So even though \cpp|flywheel_thread| is started first you should notice when you load this module and run \sh|dmesg|, that turning the crank always happens first because the flywheel thread waits for the crank thread to complete.
1656
1657
1657
-
There are other variations upon the \cpp|wait_for_completion| function, which include timeouts or being interrupted, but this basic mechanism is enough for many common situations without adding a lot of complexity.
1658
+
There are other variations of the \cpp|wait_for_completion| function, which include timeouts or being interrupted, but this basic mechanism is enough for many common situations without adding a lot of complexity.
0 commit comments