c++11 thread, condition_variable and async κ°λ μ 리
μΉ΄ν
κ³ λ¦¬ C/C++ κΈλͺ¨μ κ°μ c++11 μ thread, condition_variable(μ΄ν cv), async λ μ΄λ° κ²λ€ 곡λΆνλ€κ° λ¨Έλ¦Ώμμ΄ κΌ¬μμ΅λλ€. cvμ asyncλ₯Ό λΉκ΅νκ³ μλλΌκ΅¬μ. κ·Έλμ κ°λ
μ λͺ
ννκ² νκ³ ν·κ°λ¦¬λ λΆλΆμ μ 리ν΄λ΄€μ΅λλ€. condition_variable λ¨Όμ condition_variable(μ΄ν cv) μ λν΄μ λͺ
ννκ² μλ―Έλ₯Ό μ μνκ³ λμ΄κ°μΌκ² λ€μ. The condition_variable class is a synchronization primitive that can be used to block a thread, or multiple threads at the same time, until another thread both modifies a shared variable (the condition), and notifies the condition_variable. μΆμ² : cppreference.com std::condition_variable cvλ λκΈ°νμ κΈ°λ³Έ μμμ΄λ€. μ½κ² λ§ν΄μ λ§λλ‘ λκ³ μλ λ μ΄μμ μ°λ λμ λν΄ μλ‘ λκΈ°ν μμΌμ€ μ μλ λ°©λ²μ΄λΌλκ±°μ£ . asyncμ λΉκ΅ν΄μΌν λμμ΄ μλμμ΅λλ€. async The function template async runs the function f asynchronously μΆμ² : cppreference.com std::condition_variable function fλ₯Ό λΉλκΈ°μ μΌλ‘ μ€νμμΌμ£Όλ ν¨μ ν
νλ¦Ώμ΄λ€. asyncλ₯Ό ν΅ν΄ taskλ₯Ό μμ±νμ¬ λΉλκΈ°μ μΌλ‘ multi-threadingμ ꡬνν΄μ£Όλ ν¨μ ν
νλ¦ΏμΈκ±°μ£ . κ·Έλ¬λκΉ taskνν threadμΈκ±°μ£ . ν·κ°λ¦° λΆλΆ 첫λ²μ§Έλ, cvλ sync(λκΈ°)λ‘ μ€λͺ
νκ³ μκ³ , asyncλ async(λΉλκΈ°)λ‘ μ€λͺ
νκ³ μμ΄μ λμ΄ λλΉλλ κΈ°λ₯μΈ κ² μ²λΌ λΉκ΅νκ³ μμμ΅λλ€. λκΈ°νμ 주체, λΉλκΈ°νμ μ£Όμ²΄κ° λ¬λΌμ λΉκ΅ν λμμ΄ μλλ° λ§μ΄...