Created
October 15, 2015 08:08
-
-
Save crguezl/43107f45bc0c1ec7626c to your computer and use it in GitHub Desktop.
Example of race condition taken from Concurrency and Parallel Computing in JavaScript by Stephan Herhut on Mar 05, 2014
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
<!DOCTYPE HTML> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Asynchronous Image Loading</title> | |
</head> | |
<body> | |
<div id="holder-div"></div> | |
<script type="text/javascript"> | |
var image = new Image(100), | |
url = "http://www.infoq.com/resource/presentations/javascript-concurrency-parallelism/en/promoimage/strangeloop2013.png", //myimg.jpg | |
container = document.getElementById("holder-div"); | |
image.src = url; | |
setTimeout(function(){ | |
image.onload = function() { | |
container.appendChild(image) | |
}; | |
}, 1000); | |
</script> | |
<a href="http://www.infoq.com/presentations/javascript-concurrency-parallelism">Concurrency and Parallel Computing in JavaScript (Recorded at: StrangeLoop) by Stephan Herhut on Mar 05, 2014 </a> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See slides 10 and 11 of the talk
Concurrency and Parallel Computing in JavaScript by Stephan Herhut on Mar 05, 2014.
Play with the number of milliseconds in the
setTimeout
call.