@@ -437,15 +437,23 @@ context, though they can be implemented on top of interrupts. We'll broaden the
437
437
definition of these two marker traits to include bare metal code :
438
438
439
439
- `Sync `: types for which it is safe to share references between * execution
440
- contexts * .
440
+ contexts * that may preempt each other .
441
441
442
- - `Send `: types that can be transferred between * execution contexts * .
442
+ - `Send `: types that can be transferred between * execution contexts * that may
443
+ preempt each other .
443
444
444
445
An interrupt handler is an execution context independent of the `main ` function ,
445
446
which can be seen as the " bottom" execution context . An OS thread is also an
446
447
execution context . Each execution context has its own (call ) stack and operates
447
448
independently of other execution contexts though they can share state .
448
449
450
+ Preemption between any two execution contexts may or may not be possible . For
451
+ example , preemption can occur between two interrupt handlers if they have
452
+ different priorities , but no preemption can occur between the two if they have
453
+ the same priority . In the case of OS threads , it depends on the exact
454
+ implementation ; in the most common case , any two threads can preempt each other
455
+ because the scheduler periodically context switches between them .
456
+
449
457
Broadening the definitions of these marker traits does not change the rules
450
458
around `static ` variables . They must still hold values that implement the `Sync `
451
459
trait . Atomics implement `Sync ` so they are valid to place in `static ` variables
@@ -558,6 +566,12 @@ unsafe impl<T> Sync for Mutex<T> where T: Send {}
558
566
559
567
This constraint applies to all types of critical sections.
560
568
569
+ ### Cooperative handlers
570
+
571
+ In the case of interrupt handlers that run at the same priority and access the
572
+ same static variable (see ` examples/coop.rs ` ) no bound is required as no
573
+ preemption is possible.
574
+
561
575
### Runtime initialization
562
576
563
577
For the pattern of moving values from ` main ` to an interrupt handler this is
@@ -715,6 +729,11 @@ program has been configured to not share stateful interrupts between cores --
715
729
that is cores should * not* execute the exact same handler when the corresponding
716
730
signal arrives.
717
731
732
+ ### Cooperative handlers
733
+
734
+ The cooperative handlers pattern remains sound if and only if the handlers that
735
+ share state are serviced by a single core.
736
+
718
737
### Runtime initialization
719
738
720
739
As the runtime initialization pattern is used to initialize the "state" of
0 commit comments