kmsloop: Protect object against race conditions

Change-Id: If948d9f3c0b9027c0639150bbd547167c44d3250
kmsloop: Exit mainloop manually if the destroy function is executed by the main thread

Change-Id: I4ac7463d35c685fd73b888eb60a400ea02abdaeb
kmsloop: Do not release thread reference after a join operation

g_thread_join() consumes the reference to the passed-in thread. This will
usually cause the GThread struct and associated resources to be freed

Change-Id: I116f046936b02744a8aa3ce9faa2631b992f8ab9
kmsloop: Do not overwrite possible freed memory in thread

Change-Id: Iacd8b04bc42074c32a4c8b756d5b5aa3a6898682
kmsloop: Remove unneeded flag

Change-Id: I79acce423be2a7f7da342581945b7e9c0ce10246