@@ -36,8 +36,9 @@ is fixed.
36
36
3 . [ Synchronisation] ( ./THREADING.md#3-synchronisation )
37
37
3.1 [ Threadsafe Event] ( ./THREADING.md#31-threadsafe-event )
38
38
3.2 [ Message] ( ./THREADING.md#32-message ) A threadsafe event with data payload.
39
- 4 . [ Taming blocking functions] ( ./THREADING.md#4-taming-blocking-functions )
40
- 5 . [ Glossary] ( ./THREADING.md#5-glossary ) Terminology of realtime coding.
39
+ 4 . [ Taming blocking functions] ( ./THREADING.md#4-taming-blocking-functions ) Enabling uasyncio to handle blocking code.
40
+ 5 . [ Sharing a stream device] ( ./THREADING.md#4-sharing-a-stream-device )
41
+ 6 . [ Glossary] ( ./THREADING.md#5-glossary ) Terminology of realtime coding.
41
42
42
43
# 1. Introduction
43
44
@@ -676,7 +677,33 @@ asyncio.run(main())
676
677
```
677
678
###### [ Contents] ( ./THREADING.md#contents )
678
679
679
- # 5. Glossary
680
+ # 5. Sharing a stream device
681
+
682
+ Typical stream devices are a UART or a socket. These are typically employed to
683
+ exchange multi-byte messages between applications running on different systems.
684
+
685
+ When sharing a stream device between concurrent functions, similar issues arise
686
+ whether the functions are ` uasyncio ` tasks or code with hard concurrency. In
687
+ the case of transmission of multi-character messages a lock must be used to
688
+ ensure that transmitted characters cannot become interleaved.
689
+
690
+ In theory a lock can also be used for reception, but in practice it is rarely
691
+ feasible. Synchronising multiple receiving tasks is hard. This is because the
692
+ receiving processes seldom have precise control over the timing of the
693
+ (remote) transmitting device. It is therefore hard to determine when to
694
+ initiate each receiving process. If there is a requirement to handle
695
+ communication errors, the difficulties multiply.
696
+
697
+ The usual approach is to design the message format to enable the intended
698
+ receiving process to be determined from the message contents. The application
699
+ has a single receiving task. This parses incoming messages and routes them to
700
+ the appropriate destination. Routing may be done by the data sharing mechanisms
701
+ discussed above. Error handling may be done by the receiving process or passed
702
+ on to the message destination.
703
+
704
+ ###### [ Contents] ( ./THREADING.md#contents )
705
+
706
+ # 6. Glossary
680
707
681
708
### ISR
682
709
0 commit comments