Add Threads support to XS-code