Hi,


If I have an object taht has a method thats started as a tread and other
methods that are called by other classes.
WHat is the boundries? The methods called by other claseses are in one
thread and the threadproc in another, so we must sync those objects taht are
being shared between the called methods and the thread proc? Right?

SO basically the object itself is sitting in the caller thread, yet the
threadproc inside the object is in another. so its feet in both threads?

Thanks

Re: Object threading by Jon

Jon
Thu Oct 23 11:22:59 CDT 2003

news.microsoft.com <anonymouse@discussions.microsoft.com> wrote:
> If I have an object taht has a method thats started as a tread and other
> methods that are called by other classes.
> WHat is the boundries? The methods called by other claseses are in one
> thread and the threadproc in another, so we must sync those objects taht are
> being shared between the called methods and the thread proc? Right?
>
> SO basically the object itself is sitting in the caller thread, yet the
> threadproc inside the object is in another. so its feet in both threads?

Objects don't "sit" in threads at all. I'm not sure what you mean by
this. If data needs to be shared between threads, you need to
synchronize in order to make sure that the most up-to-date version is
seen, and to avoid race conditions etc.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Re: Object threading by AlexS

AlexS
Thu Oct 23 14:27:05 CDT 2003

If you are interested in theory of threading and concurrent systems - check
google for concurrent systems - there is a wealth of information available.
If you have some practical issue at hand it would be more productive here to
discuss this specific issue

HTH
Alex

"news.microsoft.com" <anonymouse@discussions.microsoft.com> wrote in message
news:uJumxCYmDHA.2444@TK2MSFTNGP09.phx.gbl...
> Hi,
>
>
> If I have an object taht has a method thats started as a tread and
other
> methods that are called by other classes.
> WHat is the boundries? The methods called by other claseses are in one
> thread and the threadproc in another, so we must sync those objects taht
are
> being shared between the called methods and the thread proc? Right?
>
> SO basically the object itself is sitting in the caller thread, yet the
> threadproc inside the object is in another. so its feet in both threads?
>
> Thanks
>
>



Re: Object threading by Patrik

Patrik
Thu Oct 23 12:35:55 CDT 2003


An object is allocated on the heap, the heap is shared for your current
application and in effect for all your applications threads.

So if you create an object on the heap, all your threads could share that
object and it's state. This means that if your Main thread (that every
application has) creates an object on the heap and spawns a thread that
executes a method on that object, the Main threads operation on that object
could be affected by these changes since it looks at the same data.

If you want to share an object across threads, you need to be careful in how
you handle instance fields, global object data, since all threads will
operate on the same copy of that field. This is also true for static fields.

Although when it comes to local variables, it's a totally different story
since localv ariables are stored on the stack and , in contrast to the heap,
are thread specific. Meaning that every thread has it's own copy of the
variable.

--
Patrik Löwendahl
cshrp.net - " Elegant code by witty programmers "
cornerstone.se - " IT Training for professionals "

"news.microsoft.com" <anonymouse@discussions.microsoft.com> wrote in message
news:uJumxCYmDHA.2444@TK2MSFTNGP09.phx.gbl...
> Hi,
>
>
> If I have an object taht has a method thats started as a tread and
other
> methods that are called by other classes.
> WHat is the boundries? The methods called by other claseses are in one
> thread and the threadproc in another, so we must sync those objects taht
are
> being shared between the called methods and the thread proc? Right?
>
> SO basically the object itself is sitting in the caller thread, yet the
> threadproc inside the object is in another. so its feet in both threads?
>
> Thanks
>
>



Re: Object threading by news

news
Thu Oct 23 13:16:21 CDT 2003


"Patrik Löwendahl" <patrik.lowendahl@csharpsweden.com> wrote in message
news:#YrshwYmDHA.2528@TK2MSFTNGP12.phx.gbl...
>
> An object is allocated on the heap, the heap is shared for your current
> application and in effect for all your applications threads.
>
> So if you create an object on the heap, all your threads could share that
> object and it's state. This means that if your Main thread (that every
> application has) creates an object on the heap and spawns a thread that
> executes a method on that object, the Main threads operation on that
object
> could be affected by these changes since it looks at the same data.
>
> If you want to share an object across threads, you need to be careful in
how
> you handle instance fields, global object data, since all threads will
> operate on the same copy of that field. This is also true for static
fields.
>
> Although when it comes to local variables, it's a totally different story
> since localv ariables are stored on the stack and , in contrast to the
heap,
> are thread specific. Meaning that every thread has it's own copy of the
> variable.
>
> --
> Patrik Löwendahl
> cshrp.net - " Elegant code by witty programmers "
> cornerstone.se - " IT Training for professionals "
>
> "news.microsoft.com" <anonymouse@discussions.microsoft.com> wrote in
message
> news:uJumxCYmDHA.2444@TK2MSFTNGP09.phx.gbl...
> > Hi,
> >
> >
> > If I have an object taht has a method thats started as a tread and
> other
> > methods that are called by other classes.
> > WHat is the boundries? The methods called by other claseses are in
one
> > thread and the threadproc in another, so we must sync those objects taht
> are
> > being shared between the called methods and the thread proc? Right?
> >
> > SO basically the object itself is sitting in the caller thread, yet the
> > threadproc inside the object is in another. so its feet in both threads?
> >
> > Thanks
> >
> >
>
>



Re: Object threading by news

news
Thu Oct 23 13:18:04 CDT 2003

I know about threading, just not how C# would treat it with regard to an
object method being started as a thread and that method sitting in an object
etc. basically as I see it only that method is in a thread and the variables
local to that method are in that thread but the rest is shared, so how would
a static method be different if any?


"Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
news:MPG.1a0210c07308547e98991c@msnews.microsoft.com...
> news.microsoft.com <anonymouse@discussions.microsoft.com> wrote:
> > If I have an object taht has a method thats started as a tread and
other
> > methods that are called by other classes.
> > WHat is the boundries? The methods called by other claseses are in
one
> > thread and the threadproc in another, so we must sync those objects taht
are
> > being shared between the called methods and the thread proc? Right?
> >
> > SO basically the object itself is sitting in the caller thread, yet the
> > threadproc inside the object is in another. so its feet in both threads?
>
> Objects don't "sit" in threads at all. I'm not sure what you mean by
> this. If data needs to be shared between threads, you need to
> synchronize in order to make sure that the most up-to-date version is
> seen, and to avoid race conditions etc.
>
> --
> Jon Skeet - <skeet@pobox.com>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too



Re: Object threading by Jon

Jon
Thu Oct 23 13:18:31 CDT 2003

news.microsoft.com <anonymouse@discussions.microsoft.com> wrote:
> I know about threading, just not how C# would treat it with regard to an
> object method being started as a thread and that method sitting in an object
> etc. basically as I see it only that method is in a thread and the variables
> local to that method are in that thread but the rest is shared, so how would
> a static method be different if any?

Not different at all.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too