Fixed possible instability problem in devicethread as events where deleted
from queue without locking the mutex.
Added mutex to general logging. May slow down things but hopefully work.