Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » al_lock_mutex() locks for both read and writes?

This thread is locked; no one can reply to it. rss feed Print
al_lock_mutex() locks for both read and writes?
Chris Katko
Member #1,881
January 2002
avatar

Shouldn't al_lock_mutex() allow locking separately for reading and writing?

ala

al_lock_mutex(AL_LOCK_WRITE);
al_lock_mutex(AL_LOCK_READ);
al_lock_mutex(AL_LOCK_BOTH);

http://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs

beoran
Member #12,636
March 2011

Not quite, it wouldn't be a mutex then. A mutex is to exclude other threads from access to a certain block of code, no matter if the block reads or writes.
What do you need a readers writers lock for specifically?

Elias
Member #358
May 2000

No, it's just a normal mutex not a read-write lock. You can easily implement a read-write lock using a mutex though. I think a read/write lock would be useful enough to add to Allegro's API, if someone does want to add it. However if you use C++ just use for example std::shared_lock/std::unique_lock.

--
"Either help out or stop whining" - Evert

Go to: