@@ -987,9 +987,9 @@ the [Message class](./TUTORIAL.md#39-message) uses this approach to provide an
987
987
988
988
## 3.7 Barrier
989
989
990
- This is an unofficial primitive and has no counterpart in CPython asyncio. It
991
- is based on a Microsoft primitive. While similar in purpose to ` gather ` there
992
- are differences described below.
990
+ This is an unofficial implementation of a primitive supported in
991
+ [ CPython 3.11 ] ( https://docs.python.org/3.11/library/asyncio-sync.html#asyncio.Barrier ) .
992
+ While similar in purpose to ` gather ` there are differences described below.
993
993
994
994
Its principal purpose is to cause multiple coros to rendezvous at a particular
995
995
point. For example producer and consumer coros can synchronise at a point where
@@ -2000,10 +2000,12 @@ asyncio.run(main())
2000
2000
Writing to a ` StreamWriter ` occurs in two stages. The synchronous ` .write `
2001
2001
method concatenates data for later transmission. The asynchronous ` .drain `
2002
2002
causes transmission. To avoid allocation call ` .drain ` after each call to
2003
- ` .write ` . Do not have multiple tasks calling ` .drain ` concurrently: this can
2003
+ ` .write ` . If multiple tasks are to write to the same ` StreamWriter ` , the best
2004
+ solution is to implement a shared ` Queue ` . Each task writes to the ` Queue ` and
2005
+ a single task waits on it, issuing ` .write ` and ` .drain ` whenever data is
2006
+ queued. Do not have multiple tasks calling ` .drain ` concurrently: this can
2004
2007
result in data corruption for reasons detailed
2005
- [ here] ( https://github.com/micropython/micropython/issues/6621 ) . The solution is
2006
- to use a ` Queue ` or a ` Lock ` .
2008
+ [ here] ( https://github.com/micropython/micropython/issues/6621 ) .
2007
2009
2008
2010
The mechanism works because the device driver (written in C) implements the
2009
2011
following methods: ` ioctl ` , ` read ` , ` readline ` and ` write ` . See
0 commit comments