Add thread safety support, fixes issue #64

My intention was to commit this to a branch in my fork that is based on
the current antmicro/Migrant master but I'm new to git and having
problems pulling it off under a time crunch. I will revisit this change
to better present it for push/pulling into upstream master.