BUGS
sleep() may be implemented using SIGALRM; mixing calls to alarm() and sleep() is a bad idea.
Using longjmp() from a signal handler or modifying the handling of SIGALRM while sleeping will cause undefined results.
说到了用sleep在多线程的不适合。因为是用的信号驱动来实现的。可能要引起不确定的因素。后来去网上找了下其他的方法,这里把方法贴出来。一个在多线程中比较好的实现是利用的pthread库里面的pthread_cond_timewait()函数来实现。下面贴出来代码。都比较基础。