рдкрд┐рдЫрд▓реЗ рд╣рдлреНрддреЗ C ++ рдХреА рджреБрдирд┐рдпрд╛ рдореЗрдВ рдПрдХ рджрд┐рд▓рдЪрд╕реНрдк рдШрдЯрдирд╛ рдШрдЯреАред Microsoft рдиреЗ Visual Studio 2013 рдореЗрдВ C ++ рдХрдВрдкрд╛рдЗрд▓рд░ рдХреЗ рд▓рд┐рдП рдПрдХ рдЕрдкрдбреЗрдЯ рдЬрд╛рд░реА рдХрд░рдиреЗ рдХреА
рдШреЛрд╖рдгрд╛ рдХреА рд╣реИред рдЕрдкрдиреЗ рдЖрдк рдореЗрдВ, Visual Studio рдпрд╛ рдЙрд╕рдХреЗ рд╕рд░реНрд╡рд┐рд╕ рдкреИрдХ рд╕реЗ рдЕрд▓рдЧ рд╕реЗ рдХрдВрдкрд╛рдЗрд▓рд░ рдХреЛ рдЕрдкрдбреЗрдЯ рдХрд░рдирд╛ Microsoft рдХреЗ рд▓рд┐рдП рдПрдХ рдЧреИрд░-рддреБрдЪреНрдЫ рдШрдЯрдирд╛ рд╣реИред рд▓реЗрдХрд┐рди рдЗрд╕рд╕реЗ рднреА рдЕрдзрд┐рдХ рджрд┐рд▓рдЪрд╕реНрдк рд╣реИ рдХрд┐ рдЗрд╕ рдЕрдкрдбреЗрдЯ рдореЗрдВ рдХреНрдпрд╛ рд╢рд╛рдорд┐рд▓ рд╣реИред рдкреВрд░реА рд╕реВрдЪреА рдКрдкрд░ рджрд┐рдП рдЧрдП рд▓рд┐рдВрдХ рдкрд░ рдорд┐рд▓ рд╕рдХрддреА рд╣реИ, рдФрд░ рдореИрдВ рдХреЗрд╡рд▓ рдПрдХ рдмрд┐рдВрджреБ рдкрд░ рдзреНрдпрд╛рди рдХреЗрдВрджреНрд░рд┐рдд рдХрд░реВрдВрдЧрд╛ - рдлрд┐рд░ рд╕реЗ рд╢реБрд░реВ рдХрд░рдиреЗ рдпреЛрдЧреНрдп рдХрд╛рд░реНрдпред рд╕реНрдерд┐рддрд┐ рдХреА рдкреВрд░реА рд╕рдордЭ рдХреЗ рд▓рд┐рдП: Microsoft рдиреЗ C ++ рдорд╛рдирдХреАрдХрд░рдг рд╕рдорд┐рддрд┐ рдФрд░ gcc \ clang рдбреЗрд╡рд▓рдкрд░реНрд╕ рджреЛрдиреЛрдВ рдХреА рдмрд╣реБрдд рдЕрдЪреНрдЫреА рддрд░рд╣ рд╕реЗ рд╕рдореАрдХреНрд╖рд╛ рдХреА рд╣реИ, рдкреНрд░рд╛рдпреЛрдЧрд┐рдХ рдХреЗ рдХрд╛рд░реНрдпрд╛рдиреНрд╡рдпрди рдФрд░ рднрд╡рд┐рд╖реНрдп рдХреЗ рдЕрднреА рддрдХ рд╕реНрд╡реАрдХреГрдд рд╕реБрд╡рд┐рдзрд╛рдУрдВ рдХреЗ рдЖрдзрд╛рд░ рдкрд░ рднрд╡рд┐рд╖реНрдп рдХреЗ C ++ 17 рдорд╛рдирдХ рдХреЗ рдЕрдиреБрдореЛрджрд┐рдд рдФрд░ рдЕрднреА рддрдХ рдЕрдиреБрдореЛрджрд┐рдд рд╕реБрд╡рд┐рдзрд╛рдУрдВ рдХреЗ рдХрд╛рд░реНрдпрд╛рдиреНрд╡рдпрди рдирд╣реАрдВ рдЬрд╛рд░реА рдХрд┐рдП рдЧрдП рд╣реИрдВред C ++ 14 рдорд╛рдирдХ, рдЬреЛ рдмрджрд▓реЗ рдореЗрдВ C ++ 11 рд╕реБрд╡рд┐рдзрд╛рдУрдВ рдХреЗ рд╕реБрдзрд╛рд░ рд╣реИрдВ рдЬреЛ рдЕрднреА рддрдХ рд░реЛрдЬрд╝рдорд░реНрд░рд╛ рдХреА рдкреНрд░реЛрдЧреНрд░рд╛рдорд┐рдВрдЧ рдореЗрдВ рд╢рд╛рдорд┐рд▓ рдирд╣реАрдВ рдХрд┐рдП рдЧрдП рд╣реИрдВред
рдкрд░реНрдпрд╛рдкреНрдд рдЧреАрдХ рдЪрд╛рд▓, рдЖрдкрдХреЛ рдирд╣реАрдВ рдорд┐рд▓реА?
рдФрд░ рдиреАрдЪреЗ рдмреИрдардХ рдХреЗ рдПрдХ рд▓реЗрдЦ рдХрд╛ рдЕрдиреБрд╡рд╛рдж рд╣реЛрдЧрд╛, рдЬреЛ рдЗрд╕ рд╕реБрд╡рд┐рдзрд╛ рдХреЗ рдмрд╛рд░реЗ рдореЗрдВ рдмрддрд╛рддрд╛ рд╣реИ рдФрд░ рдЗрд╕рдХрд╛ рдЙрдкрдпреЛрдЧ рдХреИрд╕реЗ рдХрд░рдирд╛ рд╣реИред
рд╣рд╛рд▓ рд╣реА рдореЗрдВ рдПрдХ BUILD рд╕рдореНрдореЗрд▓рди рдореЗрдВ, рд╣рд░реНрдм рд╕рдЯрд░
рдиреЗ C ++ рдХреЗ рднрд╡рд┐рд╖реНрдп рдХреЗ рдмрд╛рд░реЗ рдореЗрдВ
рдмрд╛рдд рдХреА ред рдЙрдирдХреА рдмрд╛рдд C ++ 11 рдФрд░ C ++ 14 рдореЗрдВ рд╕реБрдВрджрд░ рдЙрджрд╛рд╣рд░рдгреЛрдВ рд╕реЗ рднрд░реА рдереАред рдФрд░ рдЕрдЪрд╛рдирдХ, рдХрд╣реАрдВ рд╕реЗ рднреА рдмрд╛рд╣рд░ - рдПрдХ рдлрд┐рд░ рд╕реЗ рд╢реБрд░реВ рдХрд░рдиреЗ рдпреЛрдЧреНрдп рдХрд╛рд░реНрдпред рдЬрдбрд╝реА рдмреВрдЯреА, std :: future рдФрд░ resumable functions рдХрд╛ рд╡рд░реНрдгрди рдХрд░рдиреЗ рд╡рд╛рд▓реЗ рджрд╕реНрддрд╛рд╡реЗрдЬрд╝ рдХреЗ рд▓реЗрдЦрдХреЛрдВ рдореЗрдВ рд╕реЗ рдПрдХ рд╣реИ, рдЗрд╕рд▓рд┐рдП рдЙрдирдХрд╛ рдмрд╣реБрдд рдЙрд▓реНрд▓реЗрдЦ рдореЗрд░реЗ рд▓рд┐рдП рдЖрд╢реНрдЪрд░реНрдпрдЪрдХрд┐рдд рдХрд░рдиреЗ рд╡рд╛рд▓рд╛ рдирд╣реАрдВ рдерд╛, рд▓реЗрдХрд┐рди рдореБрдЭреЗ рдЖрд╢реНрдЪрд░реНрдп рд╣реБрдЖ рдХрд┐ рдЙрдиреНрд╣реЛрдВрдиреЗ рдЗрд╕ рд╡рд┐рд╖рдп рдкрд░ рдХрд┐рддрдирд╛ рдзреНрдпрд╛рди рджрд┐рдпрд╛ рдФрд░ рдЗрд╕ рддрдереНрдп рдХрд╛ рдЙрд▓реНрд▓реЗрдЦ рдХрд┐рдпрд╛ рдХрд┐ рдлрд┐рд░ рд╕реЗ рд╢реБрд░реВ рдХрд░рдирд╛ рдлрд╝рдВрдХреНрд╢рдВрд╕ рдХреЛ рд╡рд┐рдЬрд╝реБрдЕрд▓ рд╕реНрдЯреВрдбрд┐рдпреЛ 2013 рдореЗрдВ рдЕрдкрдбреЗрдЯ рдореЗрдВ рд╢рд╛рдорд┐рд▓ рдХрд┐рдпрд╛ рдЬрд╛рдПрдЧрд╛ (рднрд▓реЗ рд╣реА VS2013 рдХреА рд░рд┐рд▓реАрдЬрд╝ рдореЗрдВ рдирд╣реАрдВ, рд▓реЗрдХрд┐рди рдЖрдИрдбреАрдИ рдХреЗ рдЕрдЧрд▓реЗ рд╕рдВрд╕реНрдХрд░рдг рдХреА рддреБрд▓рдирд╛ рдореЗрдВ рдЕрднреА рднреА рдмрд╣реБрдд рдкрд╣рд▓реЗ)ред
рдореИрдВ рдПрдХ рдЫреЛрдЯреЗ рд╕реНрдкреЙрдЗрд▓рд░ рдХреЗ рд╕рд╛рде рд╢реБрд░реВ рдХрд░реВрдВрдЧрд╛: рдпрд╣ рдХрдо рд╕реЗ рдХрдо C ++ 1y рдлреАрдЪрд░ рд╣реИ, рдпрд╣ C ++ 14 рдореЗрдВ рд╢рд╛рдорд┐рд▓ рдирд╣реАрдВ рд╣реЛрдЧрд╛, рд▓реЗрдХрд┐рди рдЕрддреБрд▓реНрдпрдХрд╛рд▓рд┐рдХ рдФрд░ рд╕рдорд╛рдирд╛рдВрддрд░ рдкреНрд░реЛрдЧреНрд░рд╛рдорд┐рдВрдЧ рднрд╡рд┐рд╖реНрдп рдореЗрдВ рднрд╛рд╖рд╛ рдХреЗ рд╡рд┐рдХрд╛рд╕ рдХреА рдкреНрд░рд╡реГрддреНрддрд┐ рдореЗрдВ рд╣реЛрдЧреА, рдЗрд╕рд▓рд┐рдП рдлрд┐рд░ рд╕реЗ рд╢реБрд░реВ рд╣реЛрдиреЗ рд╡рд╛рд▓реЗ рдлрд╝рдВрдХреНрд╢рди рдирдП рдорд╛рдирдХ рдХрд╛ рдПрдХ рдХрд╛рд░реНрдмрдирд┐рдХ рд╣рд┐рд╕реНрд╕рд╛ рдмрди рдЬрд╛рдПрдВрдЧреЗред рднрд╡рд┐рд╖реНрдп рдореЗрдВ, рдЗрд╕ рд╕реБрд╡рд┐рдзрд╛ рдХреЛ рд╕рднреА рд╕рдВрдХрд▓рдХ рджреНрд╡рд╛рд░рд╛ рд╕рдорд░реНрдерд┐рдд рдХрд┐рдпрд╛ рдЬрд╛рдПрдЧрд╛, рдФрд░ рдлрд┐рд▓рд╣рд╛рд▓ Microsoft рдЕрдкрдиреЗ рд╕реНрд╡рдпрдВ рдХреЗ рдХрд╛рд░реНрдпрд╛рдиреНрд╡рдпрди рдХреЗ рд╕рд╛рде рдмрд╛рдХреА рд╕реЗ рдЖрдЧреЗ рдирд┐рдХрд▓ рд░рд╣рд╛ рд╣реИред рдпрд╣ рдХреЛрдИ рд░рд╣рд╕реНрдп рдирд╣реАрдВ рд╣реИ рдХрд┐ рдЗрд╕ рдХрд╛рд░реНрдпрдХреНрд╖рдорддрд╛ рдореЗрдВ рдПрд╕ # рдХреЗ рд╕рд╛рде async / рдкреНрд░рддреАрдХреНрд╖рд╛ рдХреЗ рд╕рд╛рде рдХреБрдЫ рд╕рд╛рджреГрд╢реНрдп рд╣реИред
рдлрд┐рд░ рд╕реЗ рд╢реБрд░реВ рдХрд░рдиреЗ рдпреЛрдЧреНрдп рдХрд╛рд░реНрдп рдХреНрдпрд╛ рд╣реИрдВ?
рдпрд╣, рд╡рд╛рд╕реНрддрд╡ рдореЗрдВ, рдореБрдЦреНрдп рдкреНрд░рд╢реНрди рд╣реИ рдЬрд┐рд╕реЗ рд╣рдо рдкрддрд╛ рд▓рдЧрд╛рдиреЗ рдХреА рдХреЛрд╢рд┐рд╢ рдХрд░ рд░рд╣реЗ рд╣реИрдВред рдЗрд╕рд╕реЗ рдкрд╣рд▓реЗ рдХрд┐ рдореИрдВ рдпрд╣
рдмрддрд╛рдирд╛ рд╢реБрд░реВ рдХрд░реВрдВ рдХрд┐ рдпрд╣ рдХреНрдпрд╛ рд╣реЛ рд╕рдХрддрд╛ рд╣реИ рдФрд░
N3650 рджрд╕реНрддрд╛рд╡реЗрдЬрд╝
рдЙрдиреНрд╣реЗрдВ рдХреИрд╕реЗ рдкрд░рд┐рднрд╛рд╖рд┐рдд рдХрд░рддрд╛
рд╣реИ , рдореБрдЭреЗ рдПрдХ рдЫреЛрдЯрд╛
рдмреНрд░реЗрдХ рд▓реЗрдирд╛ рд╣реЛрдЧрд╛ рдФрд░ рдЖрдкрдХреЛ рдпрд╣ рдмрддрд╛рдирд╛ рд╣реЛрдЧрд╛ рдХрд┐ рд╡рд╛рдпрджрд╛ рдХреНрдпрд╛ рд╣реИ, рдХреНрдпреЛрдВрдХрд┐ рдлрд┐рд░ рд╕реЗ рд╢реБрд░реВ рд╣реЛрдиреЗ рд╡рд╛рд▓реЗ рдХрд╛рд░реНрдп рдЗрд╕ рдзрд╛рд░рдгрд╛ рдкрд░ рдЖрдзрд╛рд░рд┐рдд рд╣реИрдВ рдХрд┐ рднрд╡рд┐рд╖реНрдп рдореЗрдВ .then () рдкрджреНрдзрддрд┐ рдХреЗ рд╕рд╛рде рд╡рд┐рд╕реНрддрд╛рд░ рдХрд┐рдпрд╛ рдЬрд╛рдПрдЧрд╛ред рдЬреИрд╕рд╛ рдХрд┐ рджрд╕реНрддрд╛рд╡реЗрдЬрд╝
N3634 рдореЗрдВ рд╕реБрдЭрд╛рдпрд╛ рдЧрдпрд╛ рд╣реИред рднрд╡рд┐рд╖реНрдп рдПрдХ рдЕрддреБрд▓реНрдпрдХрд╛рд▓рд┐рдХ рдСрдкрд░реЗрд╢рди рдХрд╛ рдкрд░рд┐рдгрд╛рдо рд╣реИред рдпрд╣ рдЕрддреБрд▓реНрдпрдХрд╛рд▓рд┐рдХ рдкреНрд░реЛрдЧреНрд░рд╛рдорд┐рдВрдЧ рдХреА рдмреБрдирд┐рдпрд╛рджреА рдЕрд╡рдзрд╛рд░рдгрд╛рдУрдВ рдореЗрдВ рд╕реЗ рдПрдХ рд╣реИред рднрд╡рд┐рд╖реНрдп рдПрдХ рдРрд╕реА рдЬрдЧрд╣ рд╣реИ рдЬрд╣рд╛рдВ рдЬрд╛рдирдХрд╛рд░реА рдЕрддреБрд▓реНрдпрдХрд╛рд▓рд┐рдХ рдХрд╛рд░реНрдп рдХреА рд╕реНрдерд┐рддрд┐ рдФрд░ рдЙрд╕рдХреЗ рдкрд░рд┐рдгрд╛рдо рдкрд░ рд╕рдВрдЧреНрд░рд╣реАрдд рд╣реЛрддреА рд╣реИ, рдЕрдЧрд░ рдпрд╣ рдкрд╣рд▓реЗ рд╕реЗ рд╣реА рдЙрдкрд▓рдмреНрдз рд╣реИред рдЖрдк рдкреНрд░рд╛рдкреНрдд () рд╡рд┐рдзрд┐ рдХреЛ рдХреЙрд▓ рдХрд░ рд╕рдХрддреЗ рд╣реИрдВ, рдЬреЛ рдЖрдкрдХреЗ рдкрд░рд┐рдгрд╛рдо рдХреЛ рдкреВрд░рд╛ рдХрд░рдиреЗ рдФрд░ рд╡рд╛рдкрд╕ рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП рдЕрддреБрд▓реНрдпрдХрд╛рд▓рд┐рдХ рдСрдкрд░реЗрд╢рди рдХреА рдкреНрд░рддреАрдХреНрд╖рд╛ рдХрд░реЗрдЧрд╛ (рдпрд╣ рдкрд╣рд▓реЗ рд╕реЗ рд╣реА рдорд╛рдирдХ рдореЗрдВ рд▓рд╛рдЧреВ рд╣реИ), рдпрд╛ .then () рд╡рд┐рдзрд┐ (рдЬреЛ рдЕрднреА рдорд╛рдирдХ рдореЗрдВ рдирд╣реАрдВ рд╣реИ) рдХреЗ рдорд╛рдзреНрдпрдо рд╕реЗ рдЗрд╕рдХреЗ рдкреВрд░рд╛ рд╣реЛрдиреЗ рдХреЗ рд▓рд┐рдП рд╣реИрдВрдбрд▓рд░ рдХреЛ рдкрдВрдЬреАрдХреГрдд рдХрд░реЗрдВред C ++ 11 рдореЗрдВ .then () рдХреА рдЕрдиреБрдкрд╕реНрдерд┐рддрд┐ рд╕рдмрд╕реЗ рдЕрдзрд┐рдХ рдЖрд▓реЛрдЪрдирд╛ рдХреА рдЧрдИ рддреНрд░реБрдЯрд┐рдпреЛрдВ рдореЗрдВ рд╕реЗ рдПрдХ рд╣реИ, рдЗрд╕реЗ рд╕рдВрднрд╡рддрдГ C ++ 14 рдореЗрдВ рдареАрдХ рдХрд┐рдпрд╛ рдЬрд╛рдПрдЧрд╛, рд╕рд╛рде рд╣реА std :: future рдХреЗ рд▓рд┐рдП рдХреБрдЫ рдЕрдиреНрдп рд╕реБрдзрд╛рд░реЛрдВ рдХреЗ рд╕рд╛рдеред
рд╕реА ++ 11 рдиреЗ рд▓реИрдореНрдмрджрд╛рд╕ рдХреЛ рд╕реА ++ рдореЗрдВ рдЬреЛрдбрд╝рд╛, рдЗрд╕рд▓рд┐рдП рд╕рдВрдпреЛрдЬрди рдореЗрдВ рдпрд╣ рд▓реИрдореНрдмрдбрд╛ рдлрд╝рдВрдХреНрд╢рди (рдХреЙрд▓рдмреИрдХ) рдХреЗ рд▓рд┐рдП рдЕрддреБрд▓реНрдпрдХрд╛рд▓рд┐рдХ рдХреЙрд▓ рдХреА рдПрдХ рд╢реНрд░реГрдВрдЦрд▓рд╛ рдХрд╛ рдирд┐рд░реНрдорд╛рдг рдХрд░рдирд╛ рд╕рдВрднрд╡ рдмрдирд╛рддрд╛ рд╣реИред рдЕрдм рдпрд╣ рдПрд╕рд┐рдВрдХреНрд░реЛрдирд╕ рдХрд╛рд░реНрдп рдХрд╛ рдирд┐рд╖реНрдкрд╛рджрди рд╢реБрд░реВ рдХрд░рдиреЗ рдФрд░ .then () рд╡рд┐рдзрд┐ рдХреЗ рдорд╛рдзреНрдпрдо рд╕реЗ рдкрдВрдЬреАрдХреГрдд рд╣реИрдВрдбрд▓рд░ рдореЗрдВ рдЗрд╕рдХреЗ рдкреВрд░рд╛ рд╣реЛрдиреЗ рдкрд░ рдкреНрд░рддрд┐рдХреНрд░рд┐рдпрд╛ рдХрд░рдирд╛ рд╕рдВрднрд╡ рд╣реЛрдЧрд╛ред "рд╕рд░реНрд╡рд░ рдХреА рдкреНрд░рддрд┐рдХреНрд░рд┐рдпрд╛ рдкрдврд╝реЗрдВ, рдлрд┐рд░ рдЗрд╕реЗ рдкрд╛рд░реНрд╕ рдХрд░реЗрдВ, рдлрд┐рд░ рдЗрд╕реЗ рдкреНрд░реЛрд╕реЗрд╕ рдХрд░реЗрдВ, ..." рд░рд╛рд╕реНрддреЗ рдореЗрдВ рддреНрд░реБрдЯрд┐ рдХреА рдЬрд╛рдБрдЪ рдФрд░ рд▓реЙрдЧрд┐рдВрдЧ рдХреЗ рд╕рд╛рдеред рдпрд╣ рджреГрд╖реНрдЯрд┐рдХреЛрдг рдХреБрдЫ рднрд╛рд╖рд╛рдУрдВ рдореЗрдВ рд╕рд╛рдорд╛рдиреНрдп рд╣реИ, рд▓реЗрдХрд┐рди C ++ рдореЗрдВ рдЕрднреА рддрдХ рдирд╣реАрдВ рд╣реИред рдЗрд╕ рддрд░рд╣ рдХреЗ рдПрдХ рд╢рдХреНрддрд┐рд╢рд╛рд▓реА рддрдВрддреНрд░ рдХреА рдПрдХ рдЕрдЪреНрдЫреА рд╕рдордЭ рдЖрдкрдХреЛ рднрд╡рд┐рд╖реНрдп рдореЗрдВ рдХреЛрдб рд▓рд┐рдЦрдиреЗ рдХреЗ рддрд░реАрдХреЗ рдХреЛ рдЧрдВрднреАрд░рддрд╛ рд╕реЗ рдкреНрд░рднрд╛рд╡рд┐рдд рдХрд░ рд╕рдХрддреА рд╣реИред
рдПрдХ рдЫреЛрдЯрд╛ рдЙрджрд╛рд╣рд░рдг std :: future рдкреНрд░рджрд░реНрд╢рд┐рдд рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП:
std::future<int> f_int = make_dummy_future(42); int i = f_int.get()
рдПрдХ рдлрд┐рд░ рд╕реЗ рд╢реБрд░реВ рд╣реЛрдиреЗ рд╡рд╛рд▓реЗ рдлрд╝рдВрдХреНрд╢рди рдХрд╛ рд╡рд┐рдЪрд╛рд░ рд╣реИ рдХрд┐ рд╕рдВрдХрд▓рдХ рдХреЛ рдПрдХ рджреВрд╕рд░реЗ рд╕реЗ рдЬреБрдбрд╝реЗ рд╡рд╛рдпрджрд╛ рдХреА рд╢реНрд░реГрдВрдЦрд▓рд╛ рдХреЗ рдирд┐рд░реНрдорд╛рдг рдФрд░ рдЙрдиреНрд╣реЗрдВ рд╕рд╣реА рддрд░реАрдХреЗ рд╕реЗ (ред) рдХреЗ рдорд╛рдзреНрдпрдо рд╕реЗ рдХреЙрд▓ рдХрд░рдиреЗ рдХрд╛ рдзреНрдпрд╛рди рд░рдЦрдирд╛ рдЪрд╛рд╣рд┐рдПред
рдпрд╣ рдорд╛рдирддреЗ рд╣реБрдП рджреЛ рдирдП рдХреАрд╡рд░реНрдб рдШреЛрд╖рд┐рдд рдХрд░рдХреЗ рд╕реБрдЭрд╛рд╡ рджрд┐рдпрд╛ рдЧрдпрд╛ рд╣реИ: async рдФрд░ рдкреНрд░рддреАрдХреНрд╖рд╛ рдХрд░реЗрдВред рдХреГрдкрдпрд╛ рдзреНрдпрд╛рди рджреЗрдВ рдХрд┐ рдЗрд╕рдХрд╛ std :: async рд▓рд╛рдЗрдмреНрд░реЗрд░реА рд╕реЗ рдХреЛрдИ рд▓реЗрдирд╛-рджреЗрдирд╛ рдирд╣реАрдВ рд╣реИ, рдпрд╣ рдПрдХ рдкреБрд╕реНрддрдХрд╛рд▓рдп рдирд╣реАрдВ рд╣реИ, рдпрд╣ рдкреНрд░реЛрдЧреНрд░рд╛рдорд┐рдВрдЧ рднрд╛рд╖рд╛ рдХрд╛ рдПрдХ рд╡рд┐рд╕реНрддрд╛рд░ рд╣реИред рдЗрд╕ рдлрд╝рдВрдХреНрд╢рди рдХреЛ рдЗрд╕ async рдХреАрд╡рд░реНрдб рдХреЗ рд╕рд╛рде, рдЗрд╕рдХреА рдШреЛрд╖рдгрд╛ рдХреЗ рдмрд╛рдж, рд▓реЗрдХрд┐рди рдЙрддреНрдкрдиреНрди рдЕрдкрд╡рд╛рджреЛрдВ рдХреЗ рд▓рд┐рдП рдЗрд╕рдХреЗ рд╡рд┐рдирд┐рд░реНрджреЗрд╢рди рд╕реЗ рдкрд╣рд▓реЗ рдЪрд┐рд╣реНрдирд┐рдд рдХрд┐рдпрд╛ рдЧрдпрд╛ рд╣реИ:
void resumable_function(int i) async
рддреЛ рдЕрдм рд╕рдВрдХрд▓рдХ рдЬрд╛рдирддрд╛ рд╣реИ рдХрд┐ рдпрд╣ рдПрдХ рдлрд┐рд░ рд╕реЗ рд╢реБрд░реВ рд╣реЛрдиреЗ рд╡рд╛рд▓рд╛ рдХрд╛рд░реНрдп рд╣реИред рдФрд░ рдордЬрд╛ рд╢реБрд░реВ рд╣реЛрддрд╛ рд╣реИред рд╣рд╛рд▓рд╛рдВрдХрд┐ рдпрд╣ рдПрдХ рдлрд╝рдВрдХреНрд╢рди рд╣реИ, рдпрд╣ рдЕрднреА рднреА рдХреНрд╖рдорддрд╛рдУрдВ рдореЗрдВ рдХрд╛рдлреА рд╕реАрдорд┐рдд рд╣реИред рдЗрдирдореЗрдВ рд╕реЗ рдкрд╣рд▓рд╛ рдЗрд╕рдХрд╛ рд░рд┐рдЯрд░реНрди рдкреНрд░рдХрд╛рд░ рд╣реИ - рдпрд╣ рдпрд╛ рддреЛ рд╢реВрдиреНрдп рдпрд╛ рдПрд╕рдЯреАрдбреА рд╣реЛ рд╕рдХрддрд╛ рд╣реИ: рднрд╡рд┐рд╖реНрдп / рдПрд╕рдЯреАрдбреА :: рд╕рд╛рдЭрд╛ рдХрд┐рдпрд╛ рдЧрдпрд╛ред рд╢рд╛рдпрдж рд╡реЗ рдкреНрд░рдХрд╛рд░ рдЬрд┐рдиреНрд╣реЗрдВ std рдореЗрдВ рдкрд░рд┐рд╡рд░реНрддрд┐рдд рдХрд┐рдпрд╛ рдЬрд╛ рд╕рдХрддрд╛ рд╣реИ :( рд╕рд╛рдЭрд╛_) рднрд╡рд┐рд╖реНрдп рдХреА рднреА рдЕрдиреБрдорддрд┐ рд╣реЛрдЧреА, рд▓реЗрдХрд┐рди рдЖрдо рддреМрд░ рдкрд░ рдирд┐рд╣рд┐рдд рд░реВрдкрд╛рдВрддрд░рдг рдпрд╣рд╛рдВ рд╕рдмрд╕реЗ рдЕрдЪреНрдЫрд╛ рд╕рдорд╛рдзрд╛рди рдирд╣реАрдВ рд╣реИрдВ, рдЗрд╕рд▓рд┐рдП рд╢рд╛рдпрдж рд╕рдорд┐рддрд┐ рдПрдХ рд╕рдЦреНрдд рдкреНрд░рдХрд╛рд░ рдХреЗ рдореИрдЪ рдХрд╛ рдЪрдпрди рдХрд░рдиреЗ рдХрд╛ рдирд┐рд░реНрдгрдп рд▓реЗрддреА рд╣реИред рд╡рд░реНрддрдорд╛рди рджрд╕реНрддрд╛рд╡реЗрдЬрд╝ рдЕрднреА рднреА рдЯреА рдХреА рд╡рд╛рдкрд╕реА рдХреА рдЕрдиреБрдорддрд┐ рджреЗрддрд╛ рд╣реИ, рдЗрд╕рдХрд╛ рдЕрд░реНрде рдпрд╣ рд╣реИ рдХрд┐ рдЗрд╕реЗ рдкрд░рд┐рд╡рд░реНрддрд┐рдд рдХрд░рдирд╛
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .