Reimplement async procedures using pthreads