Kayaman wrote:Because otherwise a person might try to take a cookie someone else is still holding and you end up breaking the cookie in half, giving one the chocolate part and the other the vanilla part.
2. To control access order: A person fills the cookie jar when it's empty, so he needs to wait until the jar becomes empty, and the other people need to wait while he's filling the jar.
964980 wrote:you don't understand it because you didn't study it yet. You first need to spend a good amount of time researching this material because as said - its not something you cover in a forum post. Its something that fills entire books.
Didn't understand the example you gave.
964980 wrote:That's kinda what's happening. For the duration of the synchronization, only one thread can perform the specified things. But time has nothing to do with it.
My question is why not allot time to each thread so that they can access the shared resource for that duration?
964980 wrote:Because then you'd be wasting time by making other threads sleep. They can be doing something useful at the same time. It's only when accessing shared resources that you need to synchronize the access.
So if we know the time taken by the function to print one character, why not calculate the time to print all the characters and allot that much time to that particular thread and make all other threads to sleep for that time?