stripped down version of libuv's threads code