Fix Linux multithreading race conditions.  Linux aggressively recycles closed file-handles.  OSX does not, but we should probably port these changes for safety where applicable.