Skip to content

Commit f3f4349

Browse files
committed
usb: Add a note about buffer thread safety.
This is to replace a commit which added locking here but caused some other problems. The idea behind the Buffer class is that a single producer can call pend_write() more than once and it's idempotent, however this is very complex to extend across multiple threads. Signed-off-by: Angus Gratton <angus@redyak.com.au>
1 parent 3e421b7 commit f3f4349

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

micropython/usb/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,16 @@ USB MIDI devices in MicroPython.
134134

135135
The example [midi_example.py](examples/device/midi_example.py) demonstrates how
136136
to create a simple MIDI device to send MIDI data to and from the USB host.
137+
138+
### Limitations
139+
140+
#### Buffer thread safety
141+
142+
The internal Buffer class that's used by most of the USB device classes expects data
143+
to be written to it (i.e. sent to the host) by only one thread. Bytes may be
144+
lost from the USB transfers if more than one thread (or a thread and a callback)
145+
try to write to the buffer simultaneously.
146+
147+
If writing USB data from multiple sources, your code may need to add
148+
synchronisation (i.e. locks).
149+

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