MultiThreading problem

Thread Starter

JimmyCho

Joined Aug 1, 2020
97
Hi guys ;
I'm trying to solve as much as possible multithreading problems in regard of getting a job ; I've
seen this problem of multithreading:

In the video explains the problem with complete solution but I didn't really understand how printf will print those possibilities:
(in the video mentioned that printf maybe not atomic)

2 1
1 1
2 2
1 2

could anyone please help me to illustrate in simple words the explanation that's found on the video? I already seen
the video but Im confused on his explanation and didn't understand how do I solve correctly with understandings that problem that's
found on the video (two threads racing over each other on print function).


thanks.
 

strantor

Joined Oct 3, 2010
5,543
1. Don't take programming advice from someone who types as slowly as that guy. No way he's a professional programmer.

2. That video is 38 minutes long. Nobody is going to watch it through to figure out what you're asking for. Post the time in the video at which you get confused.
 

Thread Starter

JimmyCho

Joined Aug 1, 2020
97
1. Don't take programming advice from someone who types as slowly as that guy. No way he's a professional programmer.

2. That video is 38 minutes long. Nobody is going to watch it through to figure out what you're asking for. Post the time in the video at which you get confused.
1. Don't take programming advice from someone who types as slowly as that guy. No way he's a professional programmer.

2. That video is 38 minutes long. Nobody is going to watch it through to figure out what you're asking for. Post the time in the video at which you get confused.
I understand you ; from 5:35 - 30:00 , there's four cases I didn't understand them how we get those prints (printf) from the threads of TH1 , TH2.
Thanks for your help
 

BobaMosfet

Joined Jul 1, 2009
1,767
What the guy in the video is trying to describe is what happens if you begin executing thread 1, and then get interrupted by thread 2 at various points in the print function. Where does that leave 'a'? In this case the context switcher knows that it cannot switch (or interrupt) thread 2, but must let it complete each time it's executed.

The real-world solution for this is simple. Only those who have little experience working in interrupt driven environments find this difficult. I know- I've written multi-threaded RTOSs, compilers and 6DoF (Quake-style) engines and world-editors, nuclear reactor simulators and control systems, and more.
 

Thread Starter

JimmyCho

Joined Aug 1, 2020
97
What the guy in the video is trying to describe is what happens if you begin executing thread 1, and then get interrupted by thread 2 at various points in the print function. Where does that leave 'a'? In this case the context switcher knows that it cannot switch (or interrupt) thread 2, but must let it complete each time it's executed.

The real-world solution for this is simple. Only those who have little experience working in interrupt driven environments find this difficult. I know- I've written multi-threaded RTOSs, compilers and 6DoF (Quake-style) engines and world-editors, nuclear reactor simulators and control systems, and more.
could you please illustrate for me more about your explanation after you said " Where does that leave 'a'? "
I know why it leaves a if interrupt occurs, but my questions what happens after is still confused and not understanding what happened after it leaves a ..(maybe if you illustrate exactly what could happen after it leaves a ..so it would be more clear).

In my head what Im thinking ..well an interrupt occurs and it leaves a then what?
 

nsaspook

Joined Aug 27, 2009
8,376
This thread tells me you're not ready for a programming task that involves the world of concurrency. It's time to step back and review some basic operating system programming theory.
 

Thread Starter

JimmyCho

Joined Aug 1, 2020
97
This thread tells me you're not ready for a programming task that involves the world of concurrency. It's time to step back and review some basic operating system programming theory.
But I theoretically I understand what concurrency means ..but in that problem Im struggling much.
 
Top