Libcurl - curl_multi_wakeup

Libcurl - curl_multi_wakeup

阅读函数说明curl_multi_wakeup:enter link description here

Calling this function only guarantees to wake up the current (or the next if there is no current) curl_multi_poll call, which means it is possible that multiple calls to this function will wake up the same waiting operation.

我被这句话弄糊涂了——“相同的等待操作”。怎么样?

也就是说,假设我在线程“A”的事件待机模式下有一个函数 curl_multi_poll()。

现在,例如,我从线程“B”和线程“C”调用了两次 curl_multi_wakeup() 函数。

根据这句话判断会发生什么:

...function will wake up the same waiting operation.

事实证明函数 curl_multi_poll - 只唤醒一次 ?

curl_multi_wakeup 用于等待 curl_multi_poll.

的线程池

文档说的是,如果你重复调用curl_multi_wakeup,它可能只会唤醒一个线程,而不是每次调用curl_multi_wakeup.

都唤醒一个线程。

curl_multi_poll() 是一个相对较新的调用,旨在简化等待 curl_multi_poll() 的“中断”线程。这是一个很好的解释:

https://daniel.haxx.se/blog/2019/12/09/this-is-your-wake-up-curl/

curl_multi_poll() [is a] function which asks libcurl to wait for activity on any of the involved transfers – or sleep and don’t return for the next N milliseconds.

Calling this waiting function (or using the older curl_multi_wait() or even doing a select() or poll() call “manually”) is crucial for a well-behaving program. It is important to let the code go to sleep like this when there’s nothing to do and have the system wake up it up again when it needs to do work. Failing to do this correctly, risk having libcurl instead busy-loop somewhere and that can make your application use 100% CPU during periods. That’s terribly unnecessary and bad for multiple reasons.

When ... something happens and the application for example needs to shut down immediately, users have been asking for a way to do a wake up call.

curl_multi_wakeup() explicitly makes a curl_multi_poll() function return immediately. It is designed to be possible to use from a different thread.