Created
January 6, 2012 16:01
-
-
Save arch-jslin/1571187 to your computer and use it in GitHub Desktop.
coroutine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local counter = 0 | |
local function proc1() | |
while counter < 100000000 do | |
counter = counter + 1 | |
coroutine.yield() | |
end | |
end | |
local function proc2() | |
while counter < 100000000 do | |
counter = counter + 1 | |
coroutine.yield() | |
end | |
end | |
local co1 = coroutine.create(proc1) | |
local co2 = coroutine.create(proc2) | |
while counter < 100000000 do | |
coroutine.resume(co1) | |
coroutine.resume(co2) | |
end | |
print(counter) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment