Fix multi-threading crashes on shutdown with Linux and Blackberry. Fixes issue #3133 -- thanks @unknown