Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - Is access to the Session thread-safe?

 
Thread Tools Search this Thread
Old 03-28-2005, 12:59 AM   #1
Default Is access to the Session thread-safe?


When accessing, for example, an object stored in the session such as:

Session[ "MyObject" ].MyProperty = "Some Value";

Is access to MyObject thread-safe?




Chris Newby
  Reply With Quote
Old 03-28-2005, 01:30 AM   #2
Scott Allen
 
Posts: n/a
Default Re: Is access to the Session thread-safe?

Hi Chris:

Here are some details:

ASP.NET does manage access to session state with a ReaderWriterLock.
The default is to take a writer lock, which serializes requests coming
in on the same session (using EnableSessionState="ReadOnly" takes a
reader lock and does allow concurrent request processing on a
session).

In this example, you are not really modifying session state, but
modifying an object through a reference stored in session state. If
anyone else has a reference to the same object the code is only thread
safe if MyObject is thread safe.

Know what I mean?

--
Scott
http://www.OdeToCode.com/blogs/scott/


On Sun, 27 Mar 2005 19:59:26 -0500, "Chris Newby"
<> wrote:

> When accessing, for example, an object stored in the session such as:
>
>Session[ "MyObject" ].MyProperty = "Some Value";
>
>Is access to MyObject thread-safe?
>


  Reply With Quote
Old 03-28-2005, 02:15 AM   #3
Chris Newby
 
Posts: n/a
Default Re: Is access to the Session thread-safe?

Yeah, makes perfect sense.

Could you possibly elaborate a little more on exactly when ASP.NET creates
and releases the ReaderWriter Lock?


"Scott Allen" <> wrote in message
news...
> Hi Chris:
>
> Here are some details:
>
> ASP.NET does manage access to session state with a ReaderWriterLock.
> The default is to take a writer lock, which serializes requests coming
> in on the same session (using EnableSessionState="ReadOnly" takes a
> reader lock and does allow concurrent request processing on a
> session).
>
> In this example, you are not really modifying session state, but
> modifying an object through a reference stored in session state. If
> anyone else has a reference to the same object the code is only thread
> safe if MyObject is thread safe.
>
> Know what I mean?
>
> --
> Scott
> http://www.OdeToCode.com/blogs/scott/
>
>
> On Sun, 27 Mar 2005 19:59:26 -0500, "Chris Newby"
> <> wrote:
>
> > When accessing, for example, an object stored in the session such as:
> >
> >Session[ "MyObject" ].MyProperty = "Some Value";
> >
> >Is access to MyObject thread-safe?
> >

>



  Reply With Quote
Old 03-28-2005, 03:37 AM   #4
Scott Allen
 
Posts: n/a
Default Re: Is access to the Session thread-safe?

When the SessionStateModule catches the AcquireRequestState event
during request processing. This happens before control reaches the
ASPX page handler.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sun, 27 Mar 2005 21:15:12 -0500, "Chris Newby"
<> wrote:

>Yeah, makes perfect sense.
>
>Could you possibly elaborate a little more on exactly when ASP.NET creates
>and releases the ReaderWriter Lock?
>
>


  Reply With Quote
Old 03-28-2005, 01:41 PM   #5
Chris Newby
 
Posts: n/a
Default Re: Is access to the Session thread-safe?

Thanks Scott, very helpful//

"Scott Allen" <> wrote in message
news:...
> When the SessionStateModule catches the AcquireRequestState event
> during request processing. This happens before control reaches the
> ASPX page handler.
>
> --
> Scott
> http://www.OdeToCode.com/blogs/scott/
>
> On Sun, 27 Mar 2005 21:15:12 -0500, "Chris Newby"
> <> wrote:
>
> >Yeah, makes perfect sense.
> >
> >Could you possibly elaborate a little more on exactly when ASP.NET

creates
> >and releases the ReaderWriter Lock?
> >
> >

>



  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump