G
Gerard Flanagan
### I smell Java burning...
+1 QOTW
"Mistah Kurtz - he dead."
(http://en.wikiquote.org/wiki/Heart_of_Darkness)
;-]
### I smell Java burning...
You can probably (after stripping out all the commented code) figureIt runs on my machine in 2.5. First change was to run it
indefinitely, and it's doing so. Still not conclusive evidence that
it's free of deadlocks, nor is that I don't see any by
inspection. ...But it's running.
I just picked names that seemed to represent what the piecesSecond, thanks for picking better names for the identifiers. Mine
always suck.
The order of the wake up is not, I believe, guaranteed by theThird. StepLock.acquirestep can use notifyAll: wake all of them up,
and all but one go back to sleep. However, the current implementation
wakes them up in order wait was called, so you do save some time here,
(Even though the docs say otherwise). The while self._step!= step is
suspicious, but the alternative is an -sequence- of locks, the penalty
is only large for high step lengths, and it's not exactly polling-- so
maybe that's just the purist in me.
If you look at the documentation for threading.Condition, youFourth: wait is a private member, unless you're enabling the
functionality of waiting for the next change in step by another
thread. notifyAll isn't used anywhere. condition is also private, I
believe.
History… Classical news servers used to expire articles afterFifth: My webreader gives me this information: "Note: The author of
this message requested that it not be archived. This message will be
removed from Groups in 6 days (Mar 7, 12:55 am)." Curious if you
intentially have it. It could be nice to retrieve this-- same with
Stage.
Hand analysis of the code seems to require them -- and so wouldSixth: If I comment out fmain:worktask.slock.release() and
threadbody:worker.slock.release() there is no effect. It's bizarre.
Is it a requirement to use them?
Seventh: What is the advantage of using a Condition over an Event?
I only pointed out that, on Windows, one can not use the commonI'm not sure, but you seem to be implying that the only way to use Windows'
asynchronous I/O APIs is with threads. Actually, it is possible (and Twisted
allows you) to use these as well without writing a threaded application.
Dennis Lee Bieber said:I only pointed out that, on Windows, one can not use the common
/select()/ function with files. And one rarely sees examples of coding a
Twisted-style (emphasis on style) asynchronous callback system mixing
files and network sockes using the Windows-specific API.
If using threads, the Windows asynchronous I/O isn't needed... let
the thread block until the I/O completes, then transfer the data (or a
message that the data is available) back to the main processing
thread...
You're probably right that it's rare, but when needed, using the
Windows asynchronous/overlapping API can provide a better solution
than blocking threads depending on the needs at hand, and without
involving any callbacks or Twisted-style programming.
An example of mine is high performance serial port handling as part of
a custom FHSS wireless adapter with a serial port interface to the PC.
In this case, minimizing I/O latency was crucial since delays could
mean missing a broadcast timeslot (about 15ms) on the wireless
network. A serial port isn't a disk file, but certainly a "file" in
the context of Windows handles.
Early implementations used independent threads for reading/writing to
the serial port and blocking during such operations, but that turned
out to have an undesirable amount of latency, and was also difficult
to interrupt when the threads were in a blocked condition.
Instead I created a single thread that had a loop using overlapped I/O
simultaneously in each direction as well as native Windows event
objects for aborting or signaling that there was additional data to be
written (the pending read I/O handled the read case). The main loop
was just a WaitForMultipleObjects to handle any of the I/O completion
indications, requests for more I/O or aborts. It was very high
performing (low latency) with low CPU usage - measurably better than a
multi-threaded version.
Communication with the rest of the application was through a
thread-safe bi-directional buffer object, also using native Win32
event objects. It worked similar to a queue, but by using the native
event objects I didn't have the performance inefficiencies for reads
with timeouts of the Python objects. The underlying Python primitives
don't have the timeout capability built in, so reads with timeouts get
implemented through checks for data interspersed with increasing
sleeps, which adds unnecessary latency.
Anyway, it worked extremely well, and was a much better fit for my
needs than a multi-threaded version with blocking I/O, without it
having to be Twisted-style.
-- David- Hide quoted text -
- Show quoted text -
acquires self.lock() too many times-- that is, once to call wait
("cannot wait on un-aquired lock"), and once after--- are "all
waiters" waiting back at self.acquire, just to make it to
self.notify... and only one at a time at that!? Don't waiters have to
release before another waiter can go?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.