Skip to content

Instantly share code, notes, and snippets.

@Shaun289
Last active April 1, 2022 13:34
Show Gist options
  • Save Shaun289/394fe11d3f4f54b291be4e873e0ffc45 to your computer and use it in GitHub Desktop.
Save Shaun289/394fe11d3f4f54b291be4e873e0ffc45 to your computer and use it in GitHub Desktop.
thread condition_variable and async

thread and condition_variable

                 thread1     thread2
                    |            | wait
   do_my_job        |            |
                    |            |
   notify_one       |----------->|
                    |            | wakeup
   do_my_job        |            |
      .             |            | do_my_job
      .             |            |
      .             |            | wait
   notify_one       |----------->|
                    |            |
                    |            |

async

                 thread1
          async     |          task1
                    |----------->|
          do_my_job |            | do_my_job
                    |            |
                    |            | done!
                    |            .
          get       |<-----------.
                    |
                    |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment