[Rxtx] bugs?
Dr. Douglas Lyon
lyon at docjava.com
Mon Sep 25 04:48:10 MDT 2006
Hi All,
I have made a change in the code. The problem
has gone away. It is possible that my change in
the code fixed something, I am not sure if this is
the case, however, and testing continues.
Here is the new version:
public class CommPortIdentifier implements CommPortIdentifierInterface {
private String PortName;
private boolean Available = true;
private String Owner;
private CommPortInterface commport;
private CommDriver RXTXDriver;
static CommPortIdentifier CommPortIndex;
CommPortIdentifier next;
private int PortType;
private final static boolean debug = false;
final static Object Sync;
Note that the "Sync" object is now final. This was
suggested by the Intellij IDEA ide.
A better understanding of why this might make a difference
is contained in the Technical Report:
[Manson] Manson, Jeremy and Pugh, William. Semantics of Multithreaded
Java. Department of Computer Science, University of Maryland, College
Park, CS-TR-4215
http://www.cs.umd.edu/users/jmanson/java/CS-TR-4215.ps
A data race can occur if the non-final version of the Sync
object were changed. This is outlined in Section 5, pp4, of the above report.
Thus, if the field were changed, the semantics of synchronizing
on Sync are probably not useful. Hence it should not harm, and
indeed, should help the code.
Final static fields do not have to be reloaded at synchronization points
and they must be initialized by the class in which they are defined, by
the class initialization process [Manson].
The question of why the program now works (better lucky than
smart, I always say) remains open.
- Doug
More information about the Rxtx
mailing list