Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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

void apr_sleep (apr_interval_time_t t)

Link: sleep

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top