Questions tagged [readerwriterlock]

71 questions
1
vote
1 answer

The reader writer lock I wrote backed by GCD code causes a deadlock in parallel test

I implemented this reader/writer lock in GCD, and it failed in parallel test. Can I get explanation for why it fails? This is for iOS development. The code is based on Objective C. I wrote a RWCache with reader/writer lock in GCD for data…
1
vote
2 answers

How is a ReaderWriterLock shared amongst threads? Is it implemented with a singleton?

When you want to use a ReaderWriterLock you declare it like this: ReaderWriterLock rwLock = new ReaderWriterLock; Well if you are doing that for all your different threads that are going to access some resource that you want to protect, they…
richard
  • 12,263
  • 23
  • 95
  • 151
1
vote
0 answers

why boost shared_mutex unlock_shared need to set state.upgrade to false in the last reader?

I am trying to understand to source code of boost shared_mutex, but get stuck in the unlock_shared() method. Following code copy from boost1.68, line 241 ~ 264: void unlock_shared() { boost::unique_lock lk(state_change); …
1
vote
2 answers

Why is mutex not enough?

Why do we need semaphore, condition variables and other constructs. I get that a thread getting blocked until a signal is better than a thread that takes mutex lock, checks for a condition which if doesn't pass, unlock and retry till the condition…
Parzival
  • 585
  • 2
  • 12
1
vote
1 answer

(C#) make auto GC possible for Dictionary

I maintained a dictionary of ReaderWriterLockSlim objects for resource access:(sample code is ugly here, just makes you understand my purpose) static ConcurrentDictionary rwResourceLocks = …
ineztia
  • 815
  • 1
  • 13
  • 29
1
vote
2 answers

Does a single queue with separate reader and writer threads needs locking?

I have a shared queue (implemented using a singleton queue wrapper) and a reader thread and a writer thread. I also have a mechanism to inform the reader thread when writer thread adds elements (enqueue) to the queue. Reader thread dequeue only one…
SanD
  • 503
  • 2
  • 7
  • 25
1
vote
0 answers

Readers / writer implementation using std::atomic (mutex free)

Below is an attempt at a multiple reader / writer shared data which uses std::atomics and busy waits instead of mutex and condition variables to synchronize between readers and writers. I am puzzled as to why the asserts in there are being hit. I'm…
bitwise
  • 541
  • 6
  • 16
1
vote
1 answer

Synchronize datatable/dataview for read write

I have application in .net 2.0 in which I have a DataTable object globally in my application and have different dataviews in whole application. When an action performed i have create many threads lets say 5 in which data is read from different…
ABC
  • 9
  • 1
1
vote
1 answer

ReaderWriterLock.UpgradeToWriterLock does not throw exception after timeout elapses?

I stumbled upon a really weird issue with ReaderWriterLock when writing a unit test. I tried testing UpgradeToWriterLock method with the timeout option set to 50 milliseconds. On the main thread I take the reader lock and then start numerous tasks.…
Bartosz Wójtowicz
  • 1,321
  • 10
  • 18
0
votes
5 answers

Do we need a lock in a single writer multi-reader system?

In os books they said there must be a lock to protect data from accessed by reader and writer at the same time. but when I test the simple example in x86 machine,it works well. I want to know, is the lock here nessesary? #define _GNU_SOURCE #include…
dilfish
  • 1,329
  • 2
  • 11
  • 11
0
votes
0 answers

AsyncReaderWriterLock for a server that uses LiteDB

So I am writing a server in C#. It has a LiteDB database to store messages in. When I start up the server, I also launch an async task to delete expired messages from the DB (messages that are older than some predefined threshold). Lets call this…
Ungoliant
  • 133
  • 2
  • 14
0
votes
1 answer

Implementing reader-writers lock using basic pthread objects and methods

I wish to implement a naive reader-writers lock using the basic primitives and thier respective methods that are in the pthread library (i.e. - ). I went over couple of questions and thier answers but neither satisfied what I was looking…
0
votes
0 answers

How does linux( or any OS) file system "exactly" handle concurrent file I/O (kernel's scheduling)?

I've learned about three solutions to Reader's Writer's Problem. Considering the time efficiency, I think three of them are all usable in modern OS file system. I'd like to get some clarification on how linux handles this problem. (NO ONE made a…
0
votes
1 answer

Reader writers problem using Java Threads

I have been trying to implement the reader writer problem in Java. But when the Thread.Sleep(5000) is executed, the current thread process is not interrupted. For example, when the first reader has entered the database, and the process sleeps for 5…
0
votes
1 answer

Segmentation fault (core dump) First reader-writer problem

#include #include #include #include #include int sleepval = 10, read_num = 0; int readcnt = 0, writecnt = 0; pthread_mutex_t mutex; sem_t rw_mutex; int randomGenerator(int high, int low){ …
Lunah
  • 1