Add thread safe example

It's the version I ended up with, it probably can be improved, and should be helpful for people trying to embed the library in multithreaded applications.
Merge pull request #56 from clickstefan/patch-2

Add thread safe example