Create mainloop thread