c++ - How to create a ReadWriteMutex without specifying the semaphore's resource count? -


Normal pattern for a ReadWriteMutex is to use a semaphore and to get all the resources, the author is loop:

  inline zero-written_lock () {scosdoke lock (acquisition_mutex_); (Size_t i = 0; i & lt; source_count_; ++ i) {if (sem_wait (semaphore_) <0} {fprintf (stderr, "could not get semaphore (% s) \ n", strerror (errno )); }}}  

It is fine except that you have to specify resource counting during sequential initialization and arbitrarily choosing the resource number 10 or 99 999 does not seem right. Is there a better pattern that will allow "infinite" readers (no resource counting is required)?

I found a solution: using pthread_rwlock_t (ReaderWriterLock on Windows) . These locks do not require a specific 'max_readers_count'.

I suspect that the implementation for this lock uses any type of variable to lock the entry of readers, when an author needs to write and a nuclear reader count is required.

Comparing with my house-based semaphore-based lock, it shows that the authors like (they first go).


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -