@@ -895,12 +895,9 @@ following key differences:
895
895
* It is self-clearing.
896
896
* Only one task may wait on the flag.
897
897
898
- The latter limitation may be addressed by having a task wait on a
899
- ` ThreadSafeFlag ` before setting an ` Event ` . Multiple tasks may wait on that
900
- ` Event ` .
901
-
902
898
Synchronous method:
903
899
* ` set ` Triggers the flag. Like issuing ` set ` then ` clear ` to an ` Event ` .
900
+
904
901
Asynchronous method:
905
902
* ` wait ` Wait for the flag to be set. If the flag is already set then it
906
903
returns immediately.
@@ -925,7 +922,7 @@ tim = Timer(1, freq=1, callback=cb)
925
922
926
923
asyncio.run(foo())
927
924
```
928
- Another example (posted by [ Damien] ( https://github.com/micropython/micropython/pull/6886#issuecomment-779863757 ) ):
925
+ Another example ([ posted by Damien] ( https://github.com/micropython/micropython/pull/6886#issuecomment-779863757 ) ):
929
926
``` python
930
927
class AsyncPin :
931
928
def __init__ (self , pin , trigger ):
@@ -939,16 +936,23 @@ class AsyncPin:
939
936
You then call ` await async_pin.wait_edge() ` .
940
937
941
938
The current implementation provides no performance benefits against polling the
942
- hardware. The ` ThreadSafeFlag ` uses the I/O mechanism. There are plans to
943
- reduce the latency such that I/O is polled every time the scheduler acquires
944
- control. This would provide the highest possible level of performance as
945
- discussed in
939
+ hardware: other pending tasks may be granted execution first in round-robin
940
+ fashion. However the ` ThreadSafeFlag ` uses the I/O mechanism. There is a plan
941
+ to provide a means to reduce the latency such that selected I/O devices are
942
+ polled every time the scheduler acquires control. This will provide the highest
943
+ possible level of performance as discussed in
946
944
[ Polling vs Interrupts] ( ./TUTORIAL.md#9-polling-vs-interrupts ) .
947
945
948
946
Regardless of performance issues, a key use for ` ThreadSafeFlag ` is where a
949
947
hardware device requires the use of an ISR for a μs level response. Having
950
- serviced the device, it then flags an asynchronous routine, for example to
951
- process data received.
948
+ serviced the device, the ISR flags an asynchronous routine, say to process
949
+ received data.
950
+
951
+ The fact that only one task may wait on a ` ThreadSafeFlag ` may be addressed by
952
+ having the task that waits on the ` ThreadSafeFlag ` set an ` Event ` . Multiple
953
+ tasks may wait on that ` Event ` . As an alternative to explicitly coding this,
954
+ the [ Message class] ( ./TUTORIAL.md#39-message ) uses this approach to provide an
955
+ ` Event ` -like object which can be triggered from an ISR.
952
956
953
957
###### [ Contents] ( ./TUTORIAL.md#contents )
954
958
0 commit comments