linux下怎么在等待线程结束中设置超时

2025-04-27 07:49:46
推荐回答(1个)
回答1:

有系统调用:pthread_timedjoin_np

The pthread_timedjoin_np() function performs a join-with-timeout. If thread has not yet terminated, then the call blocks until a maximum time, specified in
abstime. If the timeout expires before thread terminates, the call returns an error. The abstime argument is a structure of the following form, specifying
an absolute time measured since the Epoch (see time(2)):

struct timespec {
time_t tv_sec; /* seconds */
long tv_nsec; /* nanoseconds */
};