Home > database >  Libcurl - curl_multi_wakeup
Libcurl - curl_multi_wakeup

Time:01-01

Reading the function description 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.

I am confused by the phrase - "the same waiting operation". How's that?

That is, suppose I have a function curl_multi_poll() in event standby mode in thread "A".

Now, for example, I call the curl_multi_wakeup() function twice from thread "B" and thread "C".

And what happens judging by this phrase:

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

It turns out that the function curl_multi_poll - wakes up only once ?

CodePudding user response:

curl_multi_wakeup is meant to be used with a pool of threads waiting on curl_multi_poll.

What the document says is that if you call curl_multi_wakeup repeatedly, it will possibly wake up only a single thread, not necessarily one thread for each call to curl_multi_wakeup.

CodePudding user response:

  1. If you have no waiting threads in curl_multi_poll and you call curl_multi_wakeup 1 times, next curl_multi_poll call after all curl_multi_wakeup calls in any thread will not wait, second next curl_multi_poll call in any thread will start waiting.
  2. If you have 1 waiting threads in curl_multi_poll and you call curl_multi_wakeup 1 times, all waiting threads will wake up. Next curl_multi_poll call after all curl_multi_wakeup calls in any thread will start waiting.
  3. If you have 1 waiting threads in curl_multi_poll and you call curl_multi_wakeup 1 time, all waiting threads will wake up. Next curl_multi_poll call in any thread will have unspecified flow depending on how curl_multi_wakeup and curl_multi_poll calls are mixing.

Possible flow

thread 1               thread 2                             thread 3
   |                       |                                    |
curl_multi_wakeup (1 )     |                                    |
   |                    curl_multi_poll / exits immediately     |
   |                    curl_multi_poll                         |
   |                                                        curl_multi_poll
   |                                                            
   |                                                            
curl_multi_wakeup (1 )                                          
   |                       |                                    |
   |                       |                                curl_multi_poll
   |                    curl_multi_poll                  
   |                                                            
   |                                                            
curl_multi_wakeup                                               
   |                       |                                    |
   |                    curl_multi_poll                         |
   |                                                            |
   |                                                            |
curl_multi_wakeup                                               |    
   |                       |                                    |
   |                       |                                curl_multi_poll
   |                       |                                      
   |                       |                                      
curl_multi_wakeup          |                                    
   |                       |                                    | 
   |                       |                                    |
curl_multi_wakeup          |                                    |
curl_multi_pool / exits imm|                                    |
curl_multi_pool            |                                    |
                           |                                    |
                           |                                curl_multi_wakeup
   |                       |                                    |
   |                       |                                    |
  • Related