mod-mono-server2 with threadpool does not correct threadstatic

View: New views
5 Messages — Rating Filter:   Alert me  

mod-mono-server2 with threadpool does not correct threadstatic

by Adriaan van Kekem :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I have a mono application running with mod_mono on mono 1.2.4. I have created somewhere in my webapp a threadstatic variable, actually a generic stack with specific objects. No i am running my webapp, and seeing my log file, i see that sometimes the same thread is reused later. This is logical, because there is a threadpool containing all threads, using them later again. But when i see that the same thread is reused, the threadstatic variables are not reset. I don't know if this is a bug, from compiler view its right, because it's the same thread. But from webapplication view, i think this is not right.

Is there any solution for this, or have i to report this as a real bug?

greetings,

Adriaan

Re: mod-mono-server2 with threadpool does not correct threadstatic

by Robert Jordan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Adriaan van Kekem wrote:

> Hi,
>
> I have a mono application running with mod_mono on mono 1.2.4. I have
> created somewhere in my webapp a threadstatic variable, actually a generic
> stack with specific objects. No i am running my webapp, and seeing my log
> file, i see that sometimes the same thread is reused later. This is logical,
> because there is a threadpool containing all threads, using them later
> again. But when i see that the same thread is reused, the threadstatic
> variables are not reset. I don't know if this is a bug, from compiler view
> its right, because it's the same thread. But from webapplication view, i
> think this is not right.
>
> Is there any solution for this, or have i to report this as a real bug?

This is not a bug. As you said, the threads are reused. That's why
the [ThreadStatic] fields are already initialized.

Robert

_______________________________________________
Mono-list maillist  -  Mono-list@...
http://lists.ximian.com/mailman/listinfo/mono-list

Re: mod-mono-server2 with threadpool does not correct threadstatic

by Adriaan van Kekem :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

So, is there a possibility to solve this problem without manually clearing the stack by each new request in the global.asax? or is there no standard way to solve this problem?

greetings,

Adriaan


Robert Jordan wrote:
Adriaan van Kekem wrote:
> Hi,
>
> I have a mono application running with mod_mono on mono 1.2.4. I have
> created somewhere in my webapp a threadstatic variable, actually a generic
> stack with specific objects. No i am running my webapp, and seeing my log
> file, i see that sometimes the same thread is reused later. This is logical,
> because there is a threadpool containing all threads, using them later
> again. But when i see that the same thread is reused, the threadstatic
> variables are not reset. I don't know if this is a bug, from compiler view
> its right, because it's the same thread. But from webapplication view, i
> think this is not right.
>
> Is there any solution for this, or have i to report this as a real bug?

This is not a bug. As you said, the threads are reused. That's why
the [ThreadStatic] fields are already initialized.

Robert

_______________________________________________
Mono-list maillist  -  Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list

Re: mod-mono-server2 with threadpool does not correct threadstatic

by Michał Ziemski :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi!

If you want your variable reset after each request why delare it static?

Pleas give some further details about what are you trying to accomplish,
then maybe someone can point you to other solution.

Cheers!
Michał Ziemski

Adriaan van Kekem pisze:

> Hi,
>
> So, is there a possibility to solve this problem without manually clearing
> the stack by each new request in the global.asax? or is there no standard
> way to solve this problem?
>
> greetings,
>
> Adriaan
>
>
>
> Robert Jordan wrote:
>  
>> Adriaan van Kekem wrote:
>>    
>>> Hi,
>>>
>>> I have a mono application running with mod_mono on mono 1.2.4. I have
>>> created somewhere in my webapp a threadstatic variable, actually a
>>> generic
>>> stack with specific objects. No i am running my webapp, and seeing my log
>>> file, i see that sometimes the same thread is reused later. This is
>>> logical,
>>> because there is a threadpool containing all threads, using them later
>>> again. But when i see that the same thread is reused, the threadstatic
>>> variables are not reset. I don't know if this is a bug, from compiler
>>> view
>>> its right, because it's the same thread. But from webapplication view, i
>>> think this is not right.
>>>
>>> Is there any solution for this, or have i to report this as a real bug?
>>>      
>> This is not a bug. As you said, the threads are reused. That's why
>> the [ThreadStatic] fields are already initialized.
>>
>> Robert
>>
>> _______________________________________________
>> Mono-list maillist  -  Mono-list@...
>> http://lists.ximian.com/mailman/listinfo/mono-list
>>
>>
>>    
>
>  


_______________________________________________
Mono-list maillist  -  Mono-list@...
http://lists.ximian.com/mailman/listinfo/mono-list

Re: mod-mono-server2 with threadpool does not correct threadstatic

by Adriaan van Kekem :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

ok, great, it's better to explain why ;-)

I have implemented a scenario with using statement. So, i have created a context object which is saved in your session. But it's possible to define a sub-context, for a systemaccount to do some tasks. After the task has been done, you revert to your own context:
using(Context c = new Context())
{
   //system account tasks
}
//your own tasks

In Context i have a threadstatic variable Context.Current, which gives you your own context. This is also used in the transactionscope object of .net 2.0. So i use a Stack containing all contexts currently on stack. So, when you stop your request, the stack is still not empty, because your own context is not disposed (its saved in session object). So, when other user is using your thread from pool, the stack is not empty!

Hopefully this gives you some information what i am doing. Thank you in advance for your answer!

Adriaan


Michał Ziemski wrote:
Hi!

If you want your variable reset after each request why delare it static?

Pleas give some further details about what are you trying to accomplish,
then maybe someone can point you to other solution.

Cheers!
Michał Ziemski

Adriaan van Kekem pisze:
> Hi,
>
> So, is there a possibility to solve this problem without manually clearing
> the stack by each new request in the global.asax? or is there no standard
> way to solve this problem?
>
> greetings,
>
> Adriaan
>
>
>
> Robert Jordan wrote:
>  
>> Adriaan van Kekem wrote:
>>    
>>> Hi,
>>>
>>> I have a mono application running with mod_mono on mono 1.2.4. I have
>>> created somewhere in my webapp a threadstatic variable, actually a
>>> generic
>>> stack with specific objects. No i am running my webapp, and seeing my log
>>> file, i see that sometimes the same thread is reused later. This is
>>> logical,
>>> because there is a threadpool containing all threads, using them later
>>> again. But when i see that the same thread is reused, the threadstatic
>>> variables are not reset. I don't know if this is a bug, from compiler
>>> view
>>> its right, because it's the same thread. But from webapplication view, i
>>> think this is not right.
>>>
>>> Is there any solution for this, or have i to report this as a real bug?
>>>      
>> This is not a bug. As you said, the threads are reused. That's why
>> the [ThreadStatic] fields are already initialized.
>>
>> Robert
>>
>> _______________________________________________
>> Mono-list maillist  -  Mono-list@lists.ximian.com
>> http://lists.ximian.com/mailman/listinfo/mono-list
>>
>>
>>    
>
>  


_______________________________________________
Mono-list maillist  -  Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list