Open main menu

CDOT Wiki β

Changes

Team Darth Vector

550 bytes removed, 15:10, 17 December 2017
Lock Convoying Problem
To use a lock, you program must be working in parallel(ex #include <thread>) and should be completing something in parallel. You can find c++11 locks with #include <mutex>
Code example or Picture here ^_^<pre>#include <iostream>#include <thread> #include <mutex> //Some threads are spawned which call this function//Declared the following within the class std[[File::mutex NightsWatch;void GameOfThronesClass::GuardTheWall(){ //Protect until Unlock() is called. Only 1 thread may do this below at a time. It is //"locked"NightsWatch.Lock(); //IncrementDaysWithoutWhiteWalkerAttack++;std::cout << "It has been " << DaysWithoutWhiteWalkerAttack << " since the last attack at Castle Black!\n"; //Allow Next thread to execute the above iterationNightsWatchGpulockwhat.Unlock();  }</pre>PNG |thumb|center|700px| Mutex Example]]
Note that there can be problems with locks. If a thread is locked but it is never unlocked, any other threads will be forced to wait which may cause performance issues. Another problem is called "Dead Locking" where each thread may be waiting for another to unlock (and vice versa) and the program is forced to wait and wait .
129
edits