Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 01f45c1

Browse files
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 1d3c722 commit 01f45c1

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

‎micropython/usb/README.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,15 @@ 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).

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /