Workaround for crash FWNX-938/FWNX-946

It looks like on Linux we sometimes get a crash because we don't
have a write lock on the current thread. This change checks for the
write lock before it tries to exit it.

Change-Id: Ie771f7f98b0b7a3389beeb4bc5c21860af1b4d58