Skip to content

Commit a22b1a3

Browse files
committed
THREADING.md: Add section on stream devices.
1 parent ab6cbb6 commit a22b1a3

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

v3/docs/THREADING.md

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ is fixed.
3636
3. [Synchronisation](./THREADING.md#3-synchronisation)
3737
3.1 [Threadsafe Event](./THREADING.md#31-threadsafe-event)
3838
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.
4142

4243
# 1. Introduction
4344

@@ -676,7 +677,33 @@ asyncio.run(main())
676677
```
677678
###### [Contents](./THREADING.md#contents)
678679

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
680707

681708
### ISR
682709

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy