Tuesday, 21 February 2012

Sane Threads Fail

This weekend I decided to run the new test suite, across a 'range of machines' and all my 'testing OS's virtual machines'. These test runs showed a number of failures - segfaults on exit. Investigations showed that this is related to the calling of sane functions while within an httpd thread.

I knew that sane is not thread safe, but I thought I'd be OK if I did a 'sane_init ... sane work ... sane_exit', all within a single thread. But alas not.

So, I'm going to have to do a bit of refactoring to solve this problem. The current plan is to:
  • Move the sane_init and sane_exit in the main startup/shutdown methods.
  • Create a 'command socket' within the main block of the program.
  • Isolate sane activity from the current methods that do sane work and replace them with calls into the command socket.
  • Use a listening loop on the command socket to dispatch sane work - that will be done within the main part of the program (and not a thread).
Hopefully this will solve the problems, and has the added advantage of making 'sane and/or device' locking easier to implement. Therefore I'll be doing both of these at the same time.