Use Mutex for thread safety

Use a mutex instead of an normal instance variable to keep track of who is using the connection.

This should make the library safe to use in a threaded environment.