.NETGURU
Multi-threaded app and Thread Safety.
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.performance.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Robert May
I have a windows service that spawns multiple threads running a thing that
does a bunch of processing. Here's the code that spawns the threads:

m_totalThreads=Convert.ToInt32(Settings.GetSetting("ProcessorThreads"));

m_executingThreads=new Thread[m_totalThreads];

for (int i=0;i < m_totalThreads;i++)

{

ProcessManager processor=new ProcessManager();

m_executingThreads[i]=new Thread(new ThreadStart(processor.Process));

m_executingThreads[i].Name=i.ToString();

m_executingThreads[i].Start();

}

I haven't done a lot of multi-threaded stuff in the past, so I want to make
sure that I get this right. :)

My question is the following: Because I'm creating a new instance of the
ProcessManager for each thread, will I have problems with the classes that
the process manager spawns? Basically, do I need to worry about locking
instance variables in classes called by the processes manager that runs on
each thread?

Robert

Reply to this message...
 
    
Jon Skeet [C# MVP] (VIP)
Robert May <Click here to reveal e-mail address> wrote:
[Original message clipped]

It really depends on whether any of the data that they use is shared.
If two different process managers end up with references to the same
instances of other classes, you'll need to think about how that data is
shared. If they're dealing with entirely separate bits of data, you
don't need to worry.

See http://www.pobox.com/~skeet/csharp/multithreading.html" target="_blank">http://www.pobox.com/~skeet/csharp/multithreading.html for more
information. (It doesn't talk about this particular issue (yet!) but
you may find it handy anyway.)

--
Jon Skeet - <Click here to reveal e-mail address>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Reply to this message...
 
    
Ken Kolda
As long as the ProcessManager only invokes methods on object instances it
creates (and these instances don't share any static data), then there's no
issue. Basically, as long as the object will ever be accessed on a single
thread, there's no need for locking.

Ken

"Robert May" <Click here to reveal e-mail address> wrote in message
news:%Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
 
System.Convert
System.Threading.Thread
System.Threading.ThreadStart




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification