This series really saved me from watching boring teaching assistant videos. Greatly explained. THANK YOU A LOT.
@onurcanisler2 жыл бұрын
*LoL I agree with that:DDD*
@subbu4u Жыл бұрын
Very very good explanation...complete series is awesome
@narasarajv52783 жыл бұрын
Interesting concept for explaining the program...Thank you..
@katiabibi19663 жыл бұрын
very well explained, thank you. But I do not understand why we have "no stove available" in the beginning of execution.. aren't all stoves available at that time?
@CodeVault3 жыл бұрын
Ahh it's just the order of printing. Since we have 4 stoves and 10 cooks the first 4 get a stove (but they don't print anything) and the other 6 print out "No stove available", and only after 500ms you'll see the 4 cooks that got a stove print something. You could add the message "Started cooking..." right before: stoveFuel[i] -= fuelNeeded; usleep(500000); And should be clear
@katiabibi19663 жыл бұрын
@@CodeVault thank you so much for the answer !!!
@probexpd1916 Жыл бұрын
@@CodeVault Thank you for that answer, Sergui! I keep forgetting that with threads, the sequence of the display doesn't always correlate with what's actually happening. I added "usleep(900000)" like this... usleep(900000); printf("No stove available, wait... "); usleep(300000); Now, the output shows 4 stoves being used, 6 cooks waiting, 4 more stoves being used, 2 cooks waiting and 2 stoves being used _in sequence_
@mustafa78913 жыл бұрын
Nicely explained, it was very helpful : ) But what if a chef occupies a stove that does not have enough fuel, while some other stove have enough fuel for the chef? The chef will still go home, right?
@CodeVault3 жыл бұрын
Yea, that's what would happen. You can try and create a mechanism to try other stoves if one is empty of fuel. I kept it simple.
@prashantpatil30883 жыл бұрын
Nicely explain. Please make a video on Shared memory, Message Queue
@CodeVault3 жыл бұрын
They are on the to-do list ;)
@prashantpatil30883 жыл бұрын
@@CodeVault thanks bro.
@atjhamit2 жыл бұрын
Thanks a lot! Really appreciate the help.
@maxtirdatov3 жыл бұрын
Shouldn't i be reset to -1 after sleeping? Otherwise the stove 0 is ignored because i gets incremented before the next iteration.
@CodeVault3 жыл бұрын
Ah, you're right, that's a small mistake I made. My bad
@JamesPetts5 ай бұрын
I approve of cooking pots.
@yahmk3978 Жыл бұрын
Thank you!
@iliqnemilov60912 жыл бұрын
great video man,thanks a lot
@denizbatu78122 жыл бұрын
excellent
@beingnikhil1553 жыл бұрын
Is sleeping for some milli seconds a good practice if all the stoves are busy or we can do something better?
@CodeVault3 жыл бұрын
Definitely something better can be done. Like linking it to a condition variable and sleep until someone signals that they stopped using the stove.
@muhammetcavus69953 жыл бұрын
when if(stovefuel[i]-fuelneeded
@CodeVault3 жыл бұрын
Yes, you can. Simply unlock the mutex and then continue: pthread_mutex_unlock(&stoveMutex[i]); continue;
@Codality2 жыл бұрын
THE BEST
@Pyrografpl2 жыл бұрын
Thank you mate :-D
@HaroldX76777 ай бұрын
Maybe i should be set to -1 so that the loop will start again from 0?
@CodeVault7 ай бұрын
Which of the loops?
@qrutyq2 ай бұрын
Yep it should!
@qrutyq2 ай бұрын
@@CodeVault in the routine one. In other case it will ignore stove with index 0.
@user-yz7ts2fq9m3 жыл бұрын
Super!
@sagivalia50412 жыл бұрын
So trylock can be useful if there are more than one critical sections of the same type, right?
@CodeVault2 жыл бұрын
Yes, that's one way to use it
@kippie802 жыл бұрын
Would like to see these examples applied to some GPUs.