Skip to content

Instantly share code, notes, and snippets.

@RobinDaugherty
Last active February 10, 2016 17:41
Show Gist options
  • Save RobinDaugherty/69ac444adccbcee13bab to your computer and use it in GitHub Desktop.
Save RobinDaugherty/69ac444adccbcee13bab to your computer and use it in GitHub Desktop.
  1. check the cache and return the value if found
  2. with mutex locked 1. if the ID is currently in flight, get its condition variable 2. if ID is not in flight, check the cache again for the item
    1. if it was in the cache, return the item
    2. if not in the cache
    3. if there's room for another in-flight request 1. add a condition variable to the list of in-flight requests
  3. if the ID was already in flight, wait on the condition variable we got for it 1. when the condition variable signals, return the item from the cache
  4. if we own the new condition variable 1. make the request and store it in the cache 2. with mutex locked
    1. signal the condition variable 3. return the cached item
  5. if there was no room to add another in-flight request 1. wait on the queue-full resource
    1. start the loop over
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment