BewareMyPower opened a new pull request, #299:
URL: https://github.com/apache/pulsar-client-cpp/pull/299

   Fixes https://github.com/apache/pulsar-client-cpp/issues/298
   
   ### Motivation
   
   Currently the `Future` and `Promise` are implemented manually by managing 
conditional variables. However, the conditional variable sometimes behaviors 
incorrectly on macOS, while the existing `future` and `promise` from the C++ 
standard library works well.
   
   ### Modifications
   
   Redesign `Future` and `Promise` based on the utilities in the standard 
`<future>` header. In addition, fix the possible race condition when 
`addListener` is called after `setValue` or `setFailed`:
   - Thread 1: call `setValue`, switch existing listeners and call them one by 
one out of the lock.
   - Thread 2: call `addListener`, detect `complete_` is true and call the 
listener directly.
   
   Now, the previous listeners and the new listener are called concurrently in 
thread 1 and 2.
   
   This patch fixes the problem by locking the executions of all existing 
callbacks before modifying `complete_` to `true`.
   
   ### Verifications
   
   Run the reproduce code in #298 for 10 times and found it never failed or 
hang.
   
   ### Documentation
   
   <!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
   
   - [ ] `doc-required` 
   (Your PR needs to update docs and you will update later)
   
   - [x] `doc-not-needed` 
   (Please explain why)
   
   - [ ] `doc` 
   (Your PR contains doc changes)
   
   - [ ] `doc-complete`
   (Docs have been already added)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to