When I launch the executable file with args 1000 and 5 (1000 reading and 5 writing threads)

./a.out 1000 5

It should once in a while output HAHAHAHA~ (because there's a writer in the room) however it's not happening. Could this be possible that the algo presented in a wikipedia is wrong? If not, where's the problem?

Questions on Code Review Stack Exchange are expected to relate to code review request within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.
If this question can be reworded to fit the rules in the help center, please edit the question.

The wikipedia article looks correct. But your code is relatiely convoluted and you perform no checks to see if any of the lock/unlock calls work as expected that there could be any number of problems.
–
Loki AstariJan 2 '13 at 20:36

If a function returns an error code and you do not check the state of the error code your code will at some point break.
–
Loki AstariJan 2 '13 at 20:38

Now all you have to implement are four methods the usage of the class is short and intuitive. And most importantly the user of the RWLock can not use it incorrectly and leave the locks in the incorrect state.

So now lets implement the getXXXLock()

Notice that we use RAII to call Lock/Unlock on any lockable objects in an exception safe manor. For this we use MutexLocker which will call lock() in the constructor of the object and unlock() in the destructor when it goes out of scope. In the few cases were we can not use RAII directly we still guarantee that the calls will be made in pairs because we guarantee that for each call to getXXXLock() we will also call unlockXXX().