There is an occasional segfault that occurs in OE apps, during shutdown. The cause, I finally was able to determine, is the way OE handles threads during shutdown - which is not at all. In the attached tarball, find two patchfiles:
station_threading.patch:
- adds bgThreadFunc, netThreadFunc, and tcThreadFunc to class Station, as static member functions.
- adds a thread handle for the bg Thread, net Thread, and tc Thread to class Station as private member data.
- adds a call to pthreads_join to Station::deleteData(), which causes the main thread to wait for all child threads to complete before deleting the Station object (the source of the segfault is that the station object is deleted, while the children are still trying to use its resources.)
- Fixes a signed integer overflow in the main loops of all three ThreadFunc's, where i >0 is only true for the first 2^31-1 iterations (0x7FFFFFFF +0x1 = -0x80000000), by removing the iterators (the variable i) from the loops, and placing the starttime variable assignment outside of the loop.
threadeddevice_shutdowwait.patch:
- adds a shutdown signal by which the main thread can signal the child thread (s) to shut down
- adds a call to pthreads_join() to ThreadedDevice::stopAsync
- Fixes a signed integer overflow in the main loop of recieveThread, by removing the iterator (the variable i) from the loop, and moving the tastTime assignment to the bottom of the loop.
threadeddevice_shutdwonwait.patch is in its own patch file, because the deviceIO interface has been re-written in the current development version of OE, so this patch is potentially irrelevant.
Also, given that I am not a windows programmer, I have no idea how to handle windows threading. I did what I could, but I don't know enough about it to know what to do to join a windows thread. Thus, while I created #ifdefs to handle linux vs windows, the windows parts are empty and/or wrong, and should be looked at by a windows programmer.
all patches are against 8.10