473,785 Members | 2,289 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

read / write locks and deadlock detection

Hi,

We are creating event-driven multi-threaded applications on a daily basis.
To help us solving deadlocks, we implemented a CriticalSection class that
does dead-lock detection: an attempt to Enter() the critical section that
would cause a deadlock logs the complete deadlock loop (thread / Critical
section) and raises an exception. It has helped us a lot in the past.

However, to prevent further deadlocks, and to get a higher performance, we
want to implement read / write locks.

So, we need:
- read / write locks
- with deadlock detection
- the locks should be re-entrant (like a mutex: a thread can ask again for
the lock and gets it immediately. There is a counter inside that ensures
that the lock is only released after an equal number of calls of Leave() as
there were of Enter().

I found a good article about how to implement a read/write lock on MSDN
written by Ruediger R. Asche, but that code doesn't support re-entrance by
the same thread.

Any of you has a reference to a good article / source code / library?

I realize there are ways to avoid dead-locks:
- work with 1 worker thread (bad performance on multi-processor)
- collect data on the higher level and pass that along. That we did for as
long as the data still was contained where it belonged.

Jürgen
Nov 29 '05 #1
2 7656
"Jürgen Devlieghere" <jd************ ****@voxtron.co m> writes:
Hi,

We are creating event-driven multi-threaded applications on a daily basis.


[snip]

Try comp.programmin g.threads.

/Niklas Norrthon
Nov 29 '05 #2

Jürgen Devlieghere skrev:
Hi,

We are creating event-driven multi-threaded applications on a daily basis.
To help us solving deadlocks, we implemented a CriticalSection class that
does dead-lock detection: an attempt to Enter() the critical section that
would cause a deadlock logs the complete deadlock loop (thread / Critical
section) and raises an exception. It has helped us a lot in the past.

However, to prevent further deadlocks, and to get a higher performance, we
want to implement read / write locks.

So, we need:
- read / write locks
- with deadlock detection
- the locks should be re-entrant (like a mutex: a thread can ask again for
the lock and gets it immediately. There is a counter inside that ensures
that the lock is only released after an equal number of calls of Leave() as
there were of Enter().

I found a good article about how to implement a read/write lock on MSDN
written by Ruediger R. Asche, but that code doesn't support re-entrance by
the same thread.
Reentrancy is not something you should strive for unless it is
absolutely necessary. In my code I do checks when using reentrant
mutexes (or critical section or whatever you call the beast) that the
mutex is not locked twice by the same thread. The reason is (put
briefly) that you better know what your code is up to.
But this is all for comp.programmin g.threads where you should direct
your questions.

/Peter
[snip] Jürgen


Nov 29 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
4571
by: Duncan Grisby | last post by:
Hi, Does anyone know of a deadlock detector for Python? I don't think it would be too hard to hook into the threading module and instrument mutexes so they can be tested for deadlocks. I've googled around but I haven't found anything. Cheers, Duncan.
2
3030
by: Matt | last post by:
Hello, In my application that I'm writing in C++ (and maybe Java), specifically the cygwin flavor of C++, I want to be able to open any existing files in FAT32 or NTFS file systems (in Windows XP) for read-only purposes. In particular, I want my program to unconditionally be able to read-only open any file--and be able to read all the contents from said fail--which has been marked with any sort of "exclusionary" lock, including write...
1
2034
by: vadimar | last post by:
Hi, I would like to use database locking mechanism to control access to an external resource (like file system). What I need is 1. an exclusive (write) lock conflicting with any access to the resource (both for read and write) 2. non-exlusive (read) lock conflicting with writes only How this could be done? I'd appreciate any reply. Vadim
1
1786
by: David Arden Stevensonn | last post by:
Say I have an XML file on my website that gets read alot (by a c# aspx page) but written to occasionally (also by the same c# aspx page) . Its a simple caching situation based on time. Example: If x minutes have elapsed return the XML from the file and then rewrite the XML file for the next user and reset the clock. If x minutes havent elapsed just return the XML from the file. Do I need to be concerned for any concurrent read/writes or...
18
4893
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE) p.stdin.write("hostname\n") however, it doesn't seem to work. I think the cmd.exe is catching it.
9
1485
oll3i
by: oll3i | last post by:
read write locks public class Person { int age; rwLockMgr lockmanager; public Person() { age = 17;
0
3869
by: martinmercy2001 | last post by:
Could any body help me with creating a ring buffer class using a string. use memory circular buffer not an IO buffer. just read, write and seek method. Read method should take anumber and return the string. write method should take a string. seek should take a number and return nuthing. use three member variables a buffer itself as a string, read_position, write_position. use >>, << methods. I have tried this code but i need full...
6
7281
by: Ryan Liu | last post by:
Hi, I have some basic question about NetworkStream, can someone explain to me? Thanks a lot in advance! TcpClient has a GetStream() method return a NetworkStream for read and write. I remember there are 2 streams in Java, one for read, one for write. If I just use synchronous Read() and Write() method:
0
2873
by: TamusJRoyce | last post by:
http://nohardlockrwlocker.codeplex.com/ is a read-write locker I recently designed so hard locks are impossible. It is meant to replace ReaderWriterLock and ReaderWriterLockSlim. Upgrade locks are as simple as placing a write lock inside a read lock. It will soon have collections which utilize this locker to cache modifications while enumerations occurs to it. Then after it completes, modifications are applied. This makes enumeration...
0
9489
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10357
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10162
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5396
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4063
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2893
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.