Let’s Play a Game!

Untitled

Week 2 Questions

<aside> 🧟 Post questions you have after reading the docs and trying to make your first sketches here!

</aside>

Beatriz Ribeiro

Untitled

Brittany Price

Could you make a Quick Start for using p5.party in the Processing app? I tried to adapt the VS Code doc but I could not get hello_party to run.

Why Multiplayer is Hard Part 1: Race Conditions

Very likely, most of the code you have written is serial: the computer does only one thing at a time, your instructions are executed one after another in a sequence. Code can also run in parallel: the computer does multiple things simultaneously, two or more sequences of instructions are executed at the same time. These sequences are sometimes called threads.

Reasoning about what a piece of serial code does is sometimes hard, but reasoning about multi-threaded code is almost always much harder because you have to take into account timing.

A race condition occurs when two or more threads can access shared data and they try to change it at the same time. Because the thread scheduling algorithm can swap between threads at any time, you don't know the order in which the threads will attempt to access the shared data. Therefore, the result of the change in data is dependent on the thread scheduling algorithm, i.e. both threads are "racing" to access/change the data. — Lehane

https://stackoverflow.com/questions/34510/what-is-a-race-condition

<aside> 🧟 I’m about to take something simple and high level, and start breaking it down and looking under the hood.

It’s going to get complicated quickly, and it might get confusing. High level languages with Javascript exist because thinking about all the tiny details is overwhelming.

Just keep in mind the main point: When two sets of instructions are running at once, you might get different results depending on the specific timing of the steps.

</aside>

Lets look at a seemingly very simple example:

let a = 0;
a++;
a++;
console.log(a); // 2

The statement a++; uses shorthand for a common task: incrementing a variable

You can expand it out to a = a + 1;