Race Conditions Explained With An Example | C Programming Tutorial

  Рет қаралды 13,203

Portfolio Courses

Portfolio Courses

Күн бұрын

Пікірлер: 13
@pauldhartley
@pauldhartley 7 ай бұрын
Would this be overcome if the write_balance function was also passed the balance before the change and the new balance adjusted for any change in the read balance. So the second call to write balance would be passed 200 and 400 - it would then compare the first 200 with the current balance (500) and modifty the balance accordingly. I haven't tried this out,
@windowsbuilderthegreat3121
@windowsbuilderthegreat3121 2 жыл бұрын
How come you don’t have to include the header file in the bank.c file
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
It has to do with how C programs are compiled. But basically, the bank.c file does not need anything from the bank.h file. It can just define the functions, and that's OK, it doesn't need the function declarations in the .h file to do this. The d.c file with the main function *does* need to know the function declarations from the bank.h file so it needs to include it in order to use them. The d.c and bank.c files get compiled separately and then "linked" during the linker stage of compilation, which is where everything comes together to produce the executable program. Maybe on day I can make a video on C program compilation. 🙂
@windowsbuilderthegreat3121
@windowsbuilderthegreat3121 2 жыл бұрын
@@PortfolioCourses thanks for clarifying
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
@@windowsbuilderthegreat3121 You're welcome!
@matheusb.r.461
@matheusb.r.461 8 ай бұрын
Hi. I eventually get 300 printed. I think in this case the second thread (thread2) is executed first then thread1 writes 300. Is that correct?
@y.8901
@y.8901 7 ай бұрын
Hi, I suppose that your explanation is true, since each thread is scheduled independently (and both in parallel !), it is possible that thread1 is the last being executed
@mongraal2272
@mongraal2272 2 жыл бұрын
almost 2k bro!
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
Very exciting! The support from people has been incredible. :-)
@RaPTeN777
@RaPTeN777 Жыл бұрын
Am I the only one that realizes this function in github doesn't work. There are variables outside of scope that appear to not have any easy solution to allow the program to run. unless i'm missing something. ERROR warning: implicit declaration of function 'write_balance' [-Wimplicit-function-declaration] 63 | write_balance(account_balance);
@PortfolioCourses
@PortfolioCourses Жыл бұрын
It sounds like you're missing something when compiling it. :-) Are you missing the #include of bank.h at the top of main? That would be the simplest explanation.
@RaPTeN777
@RaPTeN777 Жыл бұрын
Honestly I was shocked I even got a response. I want to clarify that I am super new at this and am attempting to recreate this using Visual studio Code. I messed up the first time as I named all of the initial typed files the wrong extension. That said after using the github files following along with the video I am receiving a weird error still. So basically it pushes the initial value of =0 but doesn't allow the 500 value to come through because of an error relating to "(.text+0x8c): undefined reference to `read_balance'". I am not sure exactly why this is occurring. The read balance it is referring to is the second read_balance in the line: 46, 57 as well as the line 63. Idk if windows and C are just not friends and the linux mac is your friend on this one but i am not sure exactly why I can't seem to get this sorted out. I've tried everything moving { brackets around } to correct the defined functions. Any advice or place I should look at that might help point to a solution would be appreciated.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Oh OK, pthreads are a Unix/Linux/Mac way of dong threads, so that is likely going to be a problem if you want to use this code in Windows. It's technically possible to use pthreads in Windows in some ways, but Windows has its own threading functions. If you just want to play with the code for learning purposes, it should work in an online compiler like this one: www.onlinegdb.com/online_c_compiler. These compilers tend to use gcc/linux in the backend. :-)
Make A File Directory With mkdir() | C Programming Tutorial
8:16
Portfolio Courses
Рет қаралды 10 М.
Introduction To Threads (pthreads) | C Programming Tutorial
13:39
Portfolio Courses
Рет қаралды 114 М.
How to treat Acne💉
00:31
ISSEI / いっせい
Рет қаралды 108 МЛН
The Best Band 😅 #toshleh #viralshort
00:11
Toshleh
Рет қаралды 22 МЛН
REAL or FAKE? #beatbox #tiktok
01:03
BeatboxJCOP
Рет қаралды 18 МЛН
Mutex Introduction (pthreads) | C Programming Tutorial
10:19
Portfolio Courses
Рет қаралды 24 М.
int *p vs int* p Pointer Declarations | C Programming Tutorial
6:12
Portfolio Courses
Рет қаралды 142 М.
array vs &array Pointers Difference Explained | C Programming Tutorial
17:38
Function Pointers | C Programming Tutorial
18:31
Portfolio Courses
Рет қаралды 70 М.
Segmentation Faults And Common Causes | C Programming Tutorial
10:51
Portfolio Courses
Рет қаралды 6 М.
String In Char Array VS. Pointer To String Literal | C Programming Tutorial
9:58
realloc Basics
21:42
Portfolio Courses
Рет қаралды 16 М.
How To Return An Array From A Function | C Programming Tutorial
13:01
Portfolio Courses
Рет қаралды 70 М.
Function-like Macros | C Programming Tutorial
24:12
Portfolio Courses
Рет қаралды 21 М.
How to treat Acne💉
00:31
ISSEI / いっせい
Рет қаралды 108 МЛН