Race Condition....https://play.golang.org/p/FYGoflKQej

Todd McCleod, in a lesson called Race Condition, used this code
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?

1 Like

Great to see you’re stepping up to learn more. :grin: In that case, I will only breakdown smaller questions for you to discover.

For starters, we need to understand about race conditions, these are some good questions:

  1. Why do things asynchronously?
  2. What are the types of asynchronous activity available for us?
  3. Is there anything we do in our daily life that is happening asynchronously? (Provide some examples)
  4. How does a leader leads 2 or more team members in an outbound school’s outdoor competition?
  5. Say in a 100 yard sprint race with 8 competitors, how do we firmly determine who is the final winner?

These should be a good start in your journey.


I need to look that word up :smile: although I think from my distant study of Latin, I can guess at the meaning.


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.

With a stopwatch.

1 Like

wow… chill out. Have a cool lemonade. Just the simple English will do. It’s not that complicated. :sweat_smile:

In daily life? For example, say “me” and my “watch”, how do they work synchronously or asynchronously?

When is the time where “me” synchronize with my “watch”?

Good. You’re catching it. :grin:.

So can I say the judges (including referee) synchronizes the runners against a time, which is executing on its own without influencing the runners?


Lol. You’re right! But this is the type of answers that I get from Google. I rarely can get past the first sentence or two.

Now somehow lost the topic. Just beginning to learn how to navigate the site on my phone

1 Like

Ok I found it again

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?

Asynchronous I have no clue

1 Like

Interesting idea

1 Like

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. :grin:

1 Like

Interesting. A light is dawning.

as in two lines or items of code?

Very interesting.

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?
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

1 Like

Here is an interesting definition.

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

1 Like

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?

1 Like

Got it . Thanks!

By the way, I love how this site is put together.




I see.

Yes :slight_smile:

By the way, I’ve been investigating “runtime” and “sync” and am beginning to understand, but any input in layman’s terms would be appreciated.


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. :upside_down_face:

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:

  1. Have the watch announcement being pushed to an app, like push notification. Then let the notifier announce the time.
  2. 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.


Well, I thought you wanted me to close all the topics. So I randomly chose a solution. Thanks for your answer.
I pretty much understand your answer.

This, I need to investigate further.


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.