Conditions for a data race:
- Concurrency + premption or parallelism.
- Shared data.
- Mutable data.
Plan A: Restricted Concurrency, No parallelism
Stuff JS programs need to handle:
- User clicks a button.
- Request data from a server, do something when the response comes in.
- Trigger a movie to start playing.
- Accept incoming request, perform database query, send response quen query finishes.
- These things are all innately concurrent. We don't know when they'll happen.
- These things are fast to process. Most of the time the program is waiting for
some external event to occur.
- We don't need parallelism - we can use a sequential event loop.
- As an HTML page loads, each "script" tag is a job. These are scheduled to run
- Yes, external scripts are guaranteed to run in source order.
- These script tags can schedule both events and event handlers.