473,549 Members | 2,731 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Concurrency issues in reader-writer problem

Hi

I would like some ideas on way to solve the concurrency issue. The
problem is , I have an object say X which multiple readers need to
access and also to update. They do so by say two functions :
// simplistic view of the problem
Read()
{
return X;
}

Update(Y)
{
X= Y;
}

Now I would like to block any reader while calling update. With the
general solutions provided of having say a mutex and using it in Read
and Update would solve the problem. But then this would block multiple
readers also which is not desired. i.e a block on read should be
allowed only when update is called. Having a boolean and checkin is
not ideal as the atomicity of the operation is not guaranteed. Any
ideas on this?

Feb 21 '07 #1
10 3586
On 21 Feb, 11:08, "Hunk" <santosh.udyav. ..@gmail.comwro te:
Hi

I would like some ideas on way to solve the concurrency issue. The
problem is , I have an object say X which multiple readers need to
access and also to update. They do so by say two functions :
// simplistic view of the problem
Read()
{
return X;

}

Update(Y)
{
X= Y;

}

Now I would like to block any reader while calling update. With the
general solutions provided of having say a mutex and using it in Read
and Update would solve the problem. But then this would block multiple
readers also which is not desired. i.e a block on read should be
allowed only when update is called. Having a boolean and checkin is
not ideal as the atomicity of the operation is not guaranteed. Any
ideas on this?
you nead reader-writer lock. the best implementation I've
seen is Valery Pryamikov's mrsw_guard

Feb 21 '07 #2
On Feb 21, 3:08 am, "Hunk" <santosh.udyav. ..@gmail.comwro te:
Hi

I would like some ideas on way to solve the concurrency issue. The
problem is , I have an object say X which multiple readers need to
access and also to update. They do so by say two functions :
// simplistic view of the problem
Read()
{
return X;

}

Update(Y)
{
X= Y;

}

Now I would like to block any reader while calling update. With the
general solutions provided of having say a mutex and using it in Read
and Update would solve the problem. But then this would block multiple
readers also which is not desired. i.e a block on read should be
allowed only when update is called. Having a boolean and checkin is
not ideal as the atomicity of the operation is not guaranteed. Any
ideas on this?
Is this a multi-threaded program? If it is, the best solution is to
use read-write locks in pthread library. See the manpage of
pthread_rwlock_ wrlock and pthread_rwlock_ rdlock. Note that you need to
have -DUSE_UNIX98 in your compiler flags.

Feb 21 '07 #3
On Feb 21, 7:55 pm, "Bharath" <cbku...@gmail. comwrote:
On Feb 21, 3:08 am, "Hunk" <santosh.udyav. ..@gmail.comwro te:


Hi
I would like some ideas on way to solve the concurrency issue. The
problem is , I have an object say X which multiple readers need to
access and also to update. They do so by say two functions :
// simplistic view of the problem
Read()
{
return X;
}
Update(Y)
{
X= Y;
}
Now I would like to block any reader while calling update. With the
general solutions provided of having say a mutex and using it in Read
and Update would solve the problem. But then this would block multiple
readers also which is not desired. i.e a block on read should be
allowed only when update is called. Having a boolean and checkin is
not ideal as the atomicity of the operation is not guaranteed. Any
ideas on this?

Is this a multi-threaded program? If it is, the best solution is to
use read-write locks in pthread library. See the manpage of
pthread_rwlock_ wrlock and pthread_rwlock_ rdlock. Note that you need to
have -DUSE_UNIX98 in your compiler flags.- Hide quoted text -

- Show quoted text -
Thanks... yes it is a multithreaded program. i'll take a look at the
reader writer locks mentioned. Any idea on how this is implemented in
zthreads?

Feb 22 '07 #4
On Feb 21, 9:59 pm, "Hunk" <santosh.udyav. ..@gmail.comwro te:
On Feb 21, 7:55 pm, "Bharath" <cbku...@gmail. comwrote:


On Feb 21, 3:08 am, "Hunk" <santosh.udyav. ..@gmail.comwro te:
Hi
I would like some ideas on way to solve the concurrency issue. The
problem is , I have an object say X which multiple readers need to
access and also to update. They do so by say two functions :
// simplistic view of the problem
Read()
{
return X;
}
Update(Y)
{
X= Y;
}
Now I would like to block any reader while calling update. With the
general solutions provided of having say a mutex and using it in Read
and Update would solve the problem. But then this would block multiple
readers also which is not desired. i.e a block on read should be
allowed only when update is called. Having a boolean and checkin is
not ideal as the atomicity of the operation is not guaranteed. Any
ideas on this?
Is this a multi-threaded program? If it is, the best solution is to
use read-write locks in pthread library. See the manpage of
pthread_rwlock_ wrlock and pthread_rwlock_ rdlock. Note that you need to
have -DUSE_UNIX98 in your compiler flags.- Hide quoted text -
- Show quoted text -

Thanks... yes it is a multithreaded program. i'll take a look at the
reader writer locks mentioned. Any idea on how this is implemented in
zthreads?- Hide quoted text -

- Show quoted text -
I never used zthreads but this link might help.
http://zthread.sourceforge.net/html/...WriteLock.html

Feb 22 '07 #5
"dasjotre" <da******@googl email.comwrote in message
news:11******** **************@ q2g2000cwa.goog legroups.com...
On 21 Feb, 11:08, "Hunk" <santosh.udyav. ..@gmail.comwro te:
[...]
you nead reader-writer lock. the best implementation I've
seen is Valery Pryamikov's mrsw_guard
how does it compare to the following algorithm:
Feb 23 '07 #6
DOH! sorry for the other msg... I left out the link!

"dasjotre" <da******@googl email.comwrote in message
news:11******** **************@ q2g2000cwa.goog legroups.com...
On 21 Feb, 11:08, "Hunk" <santosh.udyav. ..@gmail.comwro te:
[...]
you nead reader-writer lock. the best implementation I've
seen is Valery Pryamikov's mrsw_guard
how does it compare to the following algorithm:

http://groups.google.com/group/comp....fb0ed46a4bcb4b
Feb 23 '07 #7
"Hunk" <sa************ **@gmail.comwro te in message
news:11******** *************@t 69g2000cwt.goog legroups.com...
Hi

I would like some ideas on way to solve the concurrency issue.
Sure:

http://groups.google.com/group/comp....6ad37c34dd673a

http://groups.google.com/group/comp....fb0ed46a4bcb4b

http://appcore.home.comcast.net/
How about we transfer this thread over to comp.programmin g.threads before we
go any further?
Feb 23 '07 #8
A while back I was thinking about fully integrating a working solution to
the reader-writer problem directly into the C++ STL:

http://groups.google.com/group/comp....c9c2673682d4cf
Feb 23 '07 #9
"Chris Thomasson" <cr*****@comcas t.netwrote in message
news:PZ******** *************** *******@comcast .com...
DOH! sorry for the other msg... I left out the link!

"dasjotre" <da******@googl email.comwrote in message
news:11******** **************@ q2g2000cwa.goog legroups.com...
>On 21 Feb, 11:08, "Hunk" <santosh.udyav. ..@gmail.comwro te:
[...]
>you nead reader-writer lock. the best implementation I've
seen is Valery Pryamikov's mrsw_guard

how does it compare to the following algorithm:

http://groups.google.com/group/comp....fb0ed46a4bcb4b
Or this rw-spinlock implementation:

http://appcore.home.comcast.net/appc...k_algo1_c.html

http://appcore.home.comcast.net/appc...k_algo1_h.html
Feb 23 '07 #10

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

Similar topics

3
2489
by: Robert Schuldenfrei | last post by:
Hi NG, I am looking for an opinion here. I am new to C# and SQL, being an old COBOL hand. I have started into a conversion of an old COBOL ERP system. I have a number of functions working now and it is time to decide how best to deal with the issues of concurrency. The old COBOL programs used record locking to prevent concurrency errors...
4
3091
by: Robert Schuldenfrei | last post by:
Dear NG, I was about to "improve" concurrency checking with a Timestamp when I discovered that my current code is not working. After about a day of beating my head against the wall, I am turning to the NG in hopes that someone can spot what I am doing wrong. Key to this technique working is the SQL UPDATE statement. It is designed to...
7
1124
by: Homa | last post by:
Hi, I'm thinking what will happen if two users access a page at the same time. If there are any local variable in the page, will this cause concurrency problem? Simarily, if this page need to call some functions, say logic.doSomthing(), and the class logic is a singleton (for simplicity), will there be problems?
4
2253
by: Jerry | last post by:
Hi, I have an app which retrieves data from a sql server table and displays it on a datagrid. If 2 sessions of this app are running and 2 users try to update the same record at about the same time, one of the apps will yield a concurrency violation error. The app with the error will have a little red error symbol next to the record in...
9
2015
by: corey.coughlin | last post by:
Alright, so I've been following some of the arguments about enhancing parallelism in python, and I've kind of been struck by how hard things still are. It seems like what we really need is a more pythonic approach. One thing I've been seeing suggested a lot lately is that running jobs in separate processes, to make it easy to use the latest...
13
5312
by: mfreeman | last post by:
The minimal code (VB.NET 2003) needed to show this problem is shown below. All I do is loop through the records in the table and update them without making any changes. Out of 600 records, about 40 of them throw Concurrency violation errors in the update, and my GetAllColErrs function provides no output. In comparing the rows that throw...
4
1569
by: Andrew Robinson | last post by:
I am working on a system system that requires optimistic concurrency within a web app. At first I thought this would be easy. We generate our own entities and dal/service layer but I now see that working with controls like a grid view pose some very complicated issues. If I am using rowversion, when do I start the "clock"? When I first...
4
3589
by: =?Utf-8?B?V2lsc29uIEMuSy4gTmc=?= | last post by:
Hi Experts, I am doing a prototype of providing data access (read, write & search) through Web Service. We observed that the data storing in SQL Server 2005, the memory size is always within 250MB. Our aim is to support ~50K concurrency users. After investigation, we are thinking to use In-memory database for achieving
6
1458
by: =?Utf-8?B?QmlsbGlhbQ==?= | last post by:
I am not sure if this is the right group to post to but I fugured I'd start here. Let me know if there is a more appropriate group. I wanted to try the forums before I wait 3+ hours on the phone to get a suport incident opened. I am having sever concurrenct issues with a web app running on Server 2003, IIS 6, .Net 2.0 and using SQL Server...
5
1838
by: John | last post by:
Hi I have developed the following logic to handle db concurrency violations. I just wonder if someone can tell me if it is correct or if I need a different approach.Would love to know how pros handle it. Thanks Regards
0
7518
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7446
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...
0
7715
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. ...
1
7469
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6040
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...
1
5368
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...
0
3498
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...
1
1057
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
757
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...

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.