thread-safety fixes

Easier to fix them than to argue about them with reco/core people.

@bendavid can you check that the relinking is still working?