Questions tagged [readerwriterlock]
71 questions
0
votes
0 answers
Reader Writer java with a limited number of readers
I am a Master Student and I have to write code for the classic reader writer problem with a limited number of readers at a time.
I have to write in Java using multithreading.
But without semaphore.
Only using monitors and the keyword synchronized.
I…

deborah
- 1
0
votes
2 answers
When using ReaderWriterLock does second thread actually wait or not
I am trying to write to a file using two threads. If I use ReaderWriterLock and while one thread is writing to file and second thread comes, will it actually wait for lock to release or it will just skip writing to file?

Frank Martin
- 3,147
- 16
- 52
- 73
0
votes
1 answer
Questions about ReaderWriterLockSlim. I use readerwriterlockslim to read and write, but only show write at last in console. Why?
this is code:
class program
{
static ReaderWriterLockSlim rwLock = new ReaderWriterLockSlim();
static void Main(string[] args)
{
for (int i = 0; i < 2; i++)
{
Task.Factory.StartNew(Read);
}
for…

jzian
- 23
- 5
0
votes
1 answer
What will happen if you modify the reader process in reader-writer problem?
Here is the code for the reader process (workable code)
reader(){
while(true){
P(mutex);
readerCounter++;
if((readerCount == 1)
P(OKtoaccessDB);
V(mutex);
accessDB;
readerCounter--;
if(readerCounter == 0)
…

xxColderxx
- 53
- 6
0
votes
1 answer
PThreads: Read/Write Lock: How to check if thread holds the write lock?
I am implementing a wrapper around pthread_rwlock_t for iphone dev.
Docs say that acquiring a read lock after acquiring a write lock is undefined.
Does POSIX allow me to query whether I already have the write lock?
Or, what is the best way of…

Jacko
- 12,665
- 18
- 75
- 126
0
votes
1 answer
When to wake up writer in reader-writer problem? before releasing mutex or after?
I wonder what is the best practice in my situation.
in the following code i signal the writer before unlocking the mutex
void* Reader(void *context)
{
while(TRUE)
{
LOCK(&g_mutex);
++g_activeReaders;
…

avish
- 37
- 7
0
votes
1 answer
Java concurrency problem with Servlet requests
What is the right way to solve following problem?
Writing a logic where at a same time 100 reader(Servlet requests) or one writer(Servlet requests) can be accessing critical section for one key in a map(Cache).
If writer comes into the picture in…

Vinay Sharma
- 1,163
- 1
- 10
- 20
0
votes
1 answer
Why doesnt my ReaderWriter solution work ? (java, concurrency)
So lately i ve been trying to wrap my head around concurrency. And currently I m trying to find a solution for the ReaderWriter Problem.
I got a class File, it counts the number of Readers/Writers and has two Semaphores.
When a Reader tries to read…

Coldvirus
- 45
- 10
0
votes
3 answers
Ordered Locking Pattern and ReaderWriterLock in C#
Does the ordered locking pattern prevent deadlocks when used with a ReaderWriterLock (or ReaderWriterLockSlim)?
Clearly the pattern prevents deadlocks with a mutex. Does it still prevent deadlocks if I am locking several resources with ((N…

Jason Hernandez
- 2,907
- 1
- 19
- 30
0
votes
1 answer
Segmentation fault in reader-writer appilication using posix semaphore in c
In this code, writer increment data variable and reader print this data variable. Only one writer can write any time but all reader can print data when the writer is not writing on data.The attached code run sometimes successfully but sometimes it…

Gaurang Rathod
- 13
- 1
- 1
- 5
0
votes
0 answers
Reader-Writer lock implementation
For sake of practice, I am trying to write a solution to the readers-writers problem.
The expected behavior should be that multiple reads can run concurrently, but writes need to wait for all readers to finish.
My solution is below in Read(),…

Itsik
- 3,920
- 1
- 25
- 37
0
votes
2 answers
C Segmentation Fault - readers and writers
I'm trying to implement a variation of the readers and writers problem in C, the variation is that writers can either be incrementers or decrementers and they should keep a running count. Below is the code I am trying to implement, I am getting the…

btoohey
- 141
- 1
- 1
- 12
0
votes
0 answers
multiple-readers, single-writer locks in OpenMP
There is an object shared by multiple threads to read from and write to, and I need to implement the class with a reader-writer lock which has the following functions:
It might be declared occupied by one and no more than one thread. Any other…
0
votes
0 answers
safe thread map/hashtable using AcquireSRWLock
I am providing a thin wrapper around a non-thread safe map using AcquireSRWLockShared and AcquireSRWLockExclusive Windows APIs. Essentially, lookup related methods are taking a read lock and "set" related methods are taking a write lock -- simple…

alernerdev
- 2,014
- 3
- 19
- 35
0
votes
1 answer
Reader writer lock with preference to writers
For this question simplictly , I'm having two types of computers: type A and B.
There is one computer of type A, and many of type B.
B are type of hosts which can write and read from ftp.
A is a computer which can just read from ftp.
As you might…

JavaSa
- 5,813
- 16
- 71
- 121