Todd McCleod, in a lesson called Race Condition, used this code https://play.golang.org/p/FYGoflKQej
to illustrate that Race conditions are not good code. A race condition will give unpredictable results.
I want to use this topic to understand this code and what he said, as you have taught me here on the forum, step by step.
What is “runtime” and is there a way I could figure that out myself?
What is “sync” and is there a way I could figure that out myself?
I need to look that word up although I think from my distant study of Latin, I can guess at the meaning.
COMPUTING•TELECOMMUNICATIONS
of or requiring a form of computer control timing protocol in which a specific operation begins upon receipt of an indication (signal) that the preceding operation has been completed.
Okay, I think I can get that.
So it looks like you want me to answer these questions.
What type of things? Programmingwise? If so, I don’t know.
Do you mean in Go? I think I’m just beginning to scratch the surface.
Let’s see.
not existing or happening at the same time.
Are you referring to a process? such as reading, where we read one word at a time? Or eating, when we chew one bite at a time
Hmmm. It seems he would speak to the whole team at once for pep talks, but individually for individual coaching.
The first foreign word means happening at the same time…does it not? And if I wade through the cobwebs of my distant Latin lessons, the next word would mean the opposite.
So when I put it on? Or maybe when I use it? I have a smart watch, so when I start the workout app? Or with the old fashioned type, when I set the time and date?
Yes but are the 2 entity (that happens together at the same time) interacts with each other?
Asynchronous is the opposite of synchronous, where 2 or more entities are happening at the same time but not interacting with one another.
So when you put it on, use it, start the app, set the date, the other entity (time, watch and app), working or not does not matter right? As in, you don’t actively turn the gears of your watch every second manually or tick your phone processor (like heartbeat in our heart) right?
Hence, can I say between you and the watch, both of you work asynchronously in nature because you have a heart that keeps you alive, while the watch has its own battery turning its gears?
P/s: I’ll narrow it to we-watch to stay focus on the topic.
So? I do an act (set the watch) which causes the gears to run. I act, which is asynchronous to the watch actually running.
The stopwatch example helps me to understand .
Can we look at this?
asynchronous
of or requiring a form of computer control timing protocol in which a specific operation begins upon receipt of an indication (signal) that the preceding operation has been completed. (Google)
I think I’m getting it.
OH! How I wish I had more time
Synchronous basically means that you can only execute one thing at a time. Asynchronous means that you can execute multiple things at a time and you don’t have to finish executing the current thing in order to move on to next on
No code at the moment. Entities means subjects. In our case, “we” as human is one entity and “watch” is another.
So both words originates from “synchronize”, which means interaction between 2 or more entities at a given time.
This is a case of synchronous act. The watch and you are 2 entities. However, you’re synchronizing with the watch against the time you want at a time.
These are asynchronous. When you’re not reading/setting the watch, it still ticks in order to “count” the time on its own (gears are rotating through battery powered). Both you and the watch are 2 entities but are not interacting with one another.
Similarly, the stopwatch only synchronizes with you during “starts” and “stops”. While waiting for “stops”, it has its battery to track the time, hence, became state becomes asynchronous.
So far, are we clear with synchronization between 2 entities (synchronous and asynchronous) before proceeding further?
I would suggest leave it for time being. Take a break and try closing other topics down “marked as solved”. The more you stack, the more burden and distractions you’re getting. Stay focus one thing at a time and it will get things done on-time eventually, and effectively.
Now, say you are wearing a no-screen but a speaking watch. You set it to announce the time every 15 minutes to sync up with you. Hence, the synchronous action happens every 15 minutes.
For some reason, you’re wearing 2 of these watches, one speaks English, one speaks non-English language. Both are sync exactly the same time, every 15 minutes announcement.
What happened when you hit the first 15 minutes, as a listener? Can you hear them properly when they both announce the time, in different languages, at the same time?
Not sure how this becomes a solution so I will edit it to match the question:
When 2 watches both try to announce the time in different languages, at the same time, since the listener can only listen to one at a time, both watches are racing towards the listener’s attention. That’s race condition.
To solve the racing problem while maintaining 2 watches (I’m definitely insane), the owner must explicitly control both watches’s announcement time. There are a lot of ways to do it but the notable 2 are:
Have the watch announcement being pushed to an app, like push notification. Then let the notifier announce the time.
Set one watch to announces min 15 / 45; Another announces min 0 / 30.
The first way is asynchronously messaging. All 4 entities (including app) are now free to interact with one another. This phenomenon happens all around us: from having food being cooked in the kitchen to deliver it to your table.
The second is synchronous solution where the threads are purposefully adjusted not to collide to one another. This phenomenon happens like planning you calendar, where you would not want 2 events collide at the same time.
To facilitate the first way, Go provides channel data type to do the messaging transmission.
To facilitate the second way, Go provides sync package to manage the synchronization.