Article View: borland.public.csharpbuilder.language.csharp
Article #579Re: Object locking using ReaderWriterLock
From: Sunil.P.Thomas
Date: Thu, 12 Aug 2004 13:10
Date: Thu, 12 Aug 2004 13:10
37 lines
2146 bytes
2146 bytes
Hi Marc ,
What will happen if
string sess = _loggedUsers[usn];
&
_loggedUsers.Remove(usn) will be called simultaneously (Which
is a part of RemoveUser() method).
Regards
Sunil
"Marc Rohloff [TeamB]" <"on request"> wrote in message
news:1ggdzdtzuzi58$.dlg@marcrohloff.40tude.net...
> On Thu, 12 Aug 2004 10:27:59 +0530, Sunil.P.Thomas wrote:
>
> The first thing is this code has at least 3 syntax errors and doesn't
> compile. Please post compilable code as it makes it a lot easier for
> us. Also your code has no namespace directive, it is highly
> recommended that you add one.
>
> > I want to know , is there any pitfalls in the above class ?
> No. It looks fine to me.
>
> > How we can avoid them ?
> I would have done the following which works without a lock and then
> used a simple critical section instead of a ReaderWriterLock
> (a CS is a lot more efficient than a RWLock)
>
> public static bool CanContinue(int usn , string sessionId )
> {
> string sess = _loggedUsers[usn];
> return (sess != nil) && (sess==sessionId);
> }
>
>
> --
> Marc Rohloff [TeamB]
> marc rohloff at myrealbox dot com
Technical Details
Message-ID:
<411b6aef$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<411af77e$1@newsgroups.borland.com> <1ggdzdtzuzi58$.dlg@marcrohloff.40tude.net>Show Full Headers
Complete Article Headers
X-Google-Thread: 1efe35,c5e969dc4a2fb0d X-Google-Attributes: gid1efe35,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Sunil.P.Thomas" <sunil@netlinkindia.com> Newsgroups: borland.public.csharpbuilder.language.csharp References: <411af77e$1@newsgroups.borland.com> <1ggdzdtzuzi58$.dlg@marcrohloff.40tude.net> Subject: Re: Object locking using ReaderWriterLock Date: Thu, 12 Aug 2004 18:40:11 +0530 Lines: 39 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 202.144.28.122 Message-ID: <411b6aef$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1092315887 202.144.28.122 (12 Aug 2004 06:04:47 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail