> >I have code that uses a rwlock, a mutex, a condition, and an > atomic variable > >to provide something approaching fairness (on W2K, I haven't > gotten around > >to testing this on Linux yet). I can post it if anyone is interested. > > The OS/2 implementation (locks/os2/thread_rwlock.c) I wrote also avoids > writer starvation in that it won't allow any new reader locks while a > writer is waiting. It uses 1 mutex, 1 event semaphore. It should translate > to Win32 quite easily. If you can spot any holes in my logic, > please let me > know :)
It looks like a straightforward conversion, but that's first glance. And it's late. I'll take a closer look tomorrow. How did you test for starvation? I found the testlock.c application, which appears to test read/write fine, but I'm not sure it tests specifically for starvation. [I have my own test application. It is manual in nature, requiring human review of the results, but seems to show starvation pretty well. I just ran it on Mandrake Linux 9.0 and despite the simplicity of the UNIX code (it just uses the read/write lock) there appears to be no starvation on that platform.] mma
