Threaded loops in C