Questions tagged [readwritelock]

ReadWriteLock is a structure of the two locks. From these, one locks for reading (multiple threads can access, none can modify) and another for write access (only one thread can access and also modify at time).

In Java, ReadWriteLock is a very abstract interface which provides functionality to synchronize between multiple readers and one exclusive writer.

It just assumes some structure that contains two locks. Serious problems with this interface are unlikely. If you ask something about it, probably you mean ReentrantReadWriteLock, the implementation.

Related tags:

96 questions
2
votes
3 answers

How do I determine if a thread has a lock?

I am writing an Objective-C class that I want to be thread safe. To do this I am using pthreads and a pthread_rwlock (using @synchronized is overkill and I want to learn a bit more about pthreads). The lock is inited in the objects designated init…
Benedict Cohen
  • 11,912
  • 7
  • 55
  • 67
2
votes
6 answers

Should getters/setters of primitive types be locked with ReadWriteLock in a multithreading application?

I have a Java class that is used in a multithreading application. Concurrent access is very likely. Multiple concurrent read operations should not block so I'm using a ReadWrite lock. class Example { private final ReadWriteLock lock = new…
Sven Jacobs
  • 6,278
  • 5
  • 33
  • 39
2
votes
1 answer

Are pthread read-write locks FIFO?

In the library pthread.h are pthread_rwlock_t FIFO? In the following example we have multiple threads. Imagine that every thread is guaranteed to run in order. // Thread 1 - does a write lock pthread_rwlock_wrlock(&lock); // Thread 2 - does a read…
Gary Holiday
  • 3,297
  • 3
  • 31
  • 72
2
votes
2 answers

Shrinking file that is opened in read/write

In perl: I have a file opened in read/write, with an exclusive lock. open( $f, "+< $filename" ); flock( $f, LOCK_EX ); If I write more data to the file than it previously held, the file will grow. If I write less data, my new contents are at the…
Brock
  • 160
  • 7
2
votes
1 answer

Swift pthread read/write lock taking a while to release the lock

I am trying to implement a read/write lock in Swift with the pthread API's and I have come across a strange issue. My implementation is largely based on the following with the addition of a timeout for attempted read…
Randy
  • 2,270
  • 1
  • 15
  • 24
2
votes
1 answer

Java Concurrency ReadWriteLock with my own timestamp

ReentrantReadWriteLock is perfect for read-write scenario based on timestamp programmatically at the time of reception. PUT(KEY=1,VALUE=1) PUT(KEY=1,VALUE=2) GET(KEY=1) PUT(KEY=1,VALUE=1) ... Java ReentrantReadWriteLock will automatically sync all…
Marshall An
  • 1,072
  • 2
  • 11
  • 15
2
votes
2 answers

Read a file in a while loop line-by-line while another function updates it

I am reading a file in a while loop from start to end: FILE *file; file = fopen(path_to_file), "r"); char *line = NULL; size_t len = 0; while (getline(&line, &len, file) > 0) { delete_line_from_file(line); } fclose(file); The function…
lord.garbage
  • 5,884
  • 5
  • 36
  • 55
2
votes
1 answer

Synchronizing searches and modifications

What's a good way of allowing searches from multiple threads on a list (or other data structure), but preventing searches on the list and edits to the list on different threads from interleaving? I tried using synchronized blocks in the searching…
CodeKid
  • 41
  • 4
2
votes
2 answers

How can a row be read when the table is read/write locked?

I am running these queries on MySQL 5.6.13. I using repeatable read isolation level. The table looks like below: In Session A terminal I have issued below statement UPDATE manufacurer SET lead_time = 2 WHERE mname = 'Hayleys'; In Session B…
Les_Salantes
  • 317
  • 6
  • 20
2
votes
1 answer

java - Own SeqLock implementation, would avoiding spinlock be better?

I created my own simple, compact ReadWriteLock implementation. The first one uses spinlocks upon trying to acquire a read lock. If the lock bit is set, the second avoids spinlocks by momentarily acquiring the write lock before spinning. That way, it…
Jason Sparc
  • 702
  • 2
  • 7
  • 29
2
votes
2 answers

Multiple readers / single writer lock using WinAPI

Is there a commonly used, "best practice" read-write lock WinAPI implementation? I've only found one implementation and don't know if it's reliable.
Violet Giraffe
  • 32,368
  • 48
  • 194
  • 335
2
votes
2 answers

A more succint way to use ReaderWriterLockSlim in many properties

I am trying to implement many properties that utilize ReaderWriterLockSlim for thread safety. So like most I end up with something like this in all my properties: public string Name { get { rwLock.EnterReadLock(); try { …
KrisG
  • 533
  • 4
  • 13
1
vote
2 answers

How a process release a redis lock which was not owned by this process?

I tried to implement a simple read-preferred read-write lock using 2 mutexes (using redis.lock.Lock), like what is described in this link (https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock) In the [End Read] steps, I encountered this…
Tuan Le PN
  • 364
  • 1
  • 12
1
vote
0 answers

ReadWriteLock downgrading not working as expected

I am new to Redisson and tried to implement a ReadWriteLock downgrade but after doing the release of the writeLock, Redisson is not renewing the lock even when there is still a readlock and after 30 seconds the readlock is gone. I created a simple…
1
vote
1 answer

Write lock Ntag 424DNA using makeReadOnly() throwing failed error

Creating react native NFC read/write application using https://github.com/whitedogg13/react-native-nfc-manager ->with this plugin. But I was not able to write lock after writing a NDEF record to tag. try{ await NfcManager.writeNdefMessage(bytes) …
AnAndHu S
  • 11
  • 2