简体   繁体   English

如何让 APR 线程休眠?

[英]How to sleep an APR thread?

I am using APR library to create portable multi-threading program in C++.我正在使用 APR 库在 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.问题是我需要在不需要时休眠一个线程,但手册中没有提到 function 这样做。

Do you now a way how to sleep an APR thread without need to use native system functions?你现在有一种方法可以让 APR 线程休眠而不需要使用本机系统函数吗? 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:如果您只是想将 CPU 交给其他线程,您可以使用:

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": ...在“apr_time.h”中,APR 中也有睡眠 function:

void apr_sleep (apr_interval_time_t t)

Link: sleep链接: 睡觉

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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