Closed cxbrooks closed 8 years ago
Hmm, I see that there a bunch of intermediate commits included. It would probably be best to just take the last change from 20c35e6.
I submitted a separate pull request that is against a branch that does not include intermediate commits
Under Mac OS X, running a Ptolemy model (SerialHelloWorld.xml )model was crashing Java in readArray().
The model opens two ports, writes to one port and halts after 5 seconds.
The code does not use the RXTXListener facility, instead it creates reader and writer threads.
The cause is that when the Java RXTXPort.run() method exits, a C struct named eis goes out of scope. If the drain thread tries to access eis after a timeout, then a segfault occurs.
What's happening is that in nrjavaserial/src/main/c/src/SerialImp.c, readArray() is calling read_byte_array() and read_byte_array() is crashing when eis is accessed:
The reason that it is crashing here is because eis is allocated in eventLoop() in SerialImp.c by struct event_info_struct eis:
init_threads() sets the Java eis object:
nrjavaserial/src/main/java/gnu/io/RXTXPort.java invokes eventLoop()
So, if the run() method ends, the eis automatic variable in eventloop() goes out of scope.
This pull request includes a fix for the above.
Also included is a fix for Apple, where pthread_cancel(index->drain_tid); is called instead of pthread_kill() that seems to help with crashes.