Coroutines क्या हैं
एक coroutine एक ऐसा function है जो बीच में pause हो सकता है और बाद में जहाँ छोड़ा था वहीं से resume हो सकता है।
In this page:
Coroutines क्या हैं
एक coroutine अपने stack के साथ execution का एक independent thread है, लेकिन एक समय पर सिर्फ एक चलता है। यह तब तक चलता है जब तक यह yield न करे या खत्म न हो, और control explicitly वापस pass होता है, जिसे cooperative multitasking कहते हैं। Coroutines operating-system threads नहीं हैं और कभी parallel में नहीं चलते।
Note:
Lua में Coroutines का type "thread" है, और इनमें से हज़ारों बनाना सस्ता है।
उदाहरण: What are coroutines
local co = coroutine.create(function()
print("inside the coroutine")
end)
print(type(co))
print("before resume")
coroutine.resume(co)
print("after resume")
-- Output:
-- thread
-- before resume
-- inside the coroutine
-- after resume
Login to try C/C++/Java/PHP code in the editor
आम गलतियां
- यह सोचना कि coroutines parallel में चलते हैं
- यह उम्मीद करना कि एक coroutine बनते ही चलेगा
- इन्हें operating-system threads से confuse करना
चैप्टर सारांश
- Coroutines pause और resume होते हैं
- एक समय पर सिर्फ एक चलता है
- ये cooperatively switch होते हैं
- इनका type thread है
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: