Created
August 17, 2012 22:18
-
-
Save thecodedrift/3383219 to your computer and use it in GitHub Desktop.
JS Threads
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
| var foo_count = 0; | |
| var bar_count = 0; | |
| var foo = function() { | |
| ++foo_count; | |
| window.setTimeout(bar, 5); | |
| }; | |
| var bar = function() { | |
| ++bar_count; | |
| alert("foo="+foo_count+", bar="+bar_count); | |
| }; | |
| // triggers | |
| window.setTimeout(foo, 10); | |
| window.setTimeout(bar, 20); | |
| // end triggers |
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
| sub process | |
| lock = get lock | |
| if not lock owner | |
| retry sub process in N ms (sleep) | |
| return | |
| lock was obtained | |
| perform critical code | |
| release lock | |
| non critical segment here | |
| end process |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment