Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #31186 > unrolled thread
| Started by | Dieter Maurer <dieter@handshake.de> |
|---|---|
| First post | 2012-10-13 08:35 +0200 |
| Last post | 2012-10-13 08:35 +0200 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: deque and thread-safety Dieter Maurer <dieter@handshake.de> - 2012-10-13 08:35 +0200
| From | Dieter Maurer <dieter@handshake.de> |
|---|---|
| Date | 2012-10-13 08:35 +0200 |
| Subject | Re: deque and thread-safety |
| Message-ID | <mailman.2106.1350110132.27098.python-list@python.org> |
Christophe Vandeplas <christophe@vandeplas.com> writes: > ... > From the documentation I understand that deques are thread-safe: >> Deques are a generalization of stacks and queues (the name is pronounced “deck” >> and is short for “double-ended queue”). Deques support thread-safe, memory >> efficient appends and pops from either side of the deque with approximately the >> same O(1) performance in either direction. > > It seems that appending to deques is indeed thread-safe, but not > iterating over them. You are right. And when you think about it, then there is not much point in striving for thread safety for iteration (alone). Iteration is (by nature) a non atomic operation: you iterate because you want to do something with the intermediate results; this "doing" is not part of the iteration itself. Thus, you are looking for thread safety not for only the iteration but for the iteration combined with additional operations (which may well extend beyond the duration of the iteration). Almost surely, the "deque" implementation is using locks to ensure thread safety for its "append" and "pop". Check whether this lock is exposed to the application. In this case, use it to protect you atomic sections involving iteration.
Back to top | Article view | comp.lang.python
csiph-web