473,396 Members | 1,767 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 7628
"Jürgen Devlieghere" <jd****************@voxtron.com> writes:
Hi,

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


[snip]

Try comp.programming.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.programming.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
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...
2
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...
1
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...
1
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...
18
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)...
9
oll3i
by: oll3i | last post by:
read write locks public class Person { int age; rwLockMgr lockmanager; public Person() { age = 17;
0
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...
6
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...
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.