Properly take the thread mutex before entering the mainloop

This fixes a bug similar to https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=758619 :
with glib2 >= 2.42, galicaster fails with the message
Attempt to unlock mutex that was not locked

This patch solves this issue.