简体   繁体   中英

How to sleep an APR thread?

I am using APR library to create portable multi-threading program in C++. Problem is I need to sleep a thread when it is not needed but there is no function mentioned in manual to do so.

Do you now a way how to sleep an APR thread without need to use native system functions? I would like to avoid any OS specific code. Thank you.

If you simply want to hand over CPU to other thread, you can use:

void apr_thread_yield(void);

Otherwise, you can use:

apr_status_t apr_thread_cond_timedwait(
        apr_thread_cond_t *     cond,
        apr_thread_mutex_t *    mutex,
        apr_interval_time_t     timeout  
    );

or

apr_status_t apr_thread_cond_wait(
        apr_thread_cond_t *     cond,
        apr_thread_mutex_t *    mutex
    );

Refer to here .

...and there is a sleep function in APR too, in "apr_time.h":

void apr_sleep (apr_interval_time_t t)

Link: sleep

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM