Re: Global data concurrent access ?



"Kunal" <koolkunal@xxxxxxxxx> wrote
There are about 10 new threads created per second. Threads do some
processing and die. All threads process based on data read from the
global structure.

You want to abandon this architecture as quickly as you can. The cost of
creating and destroying threads is very high, and at 10 threads per second,
you're application is spending 95% of it's time creating threads, and 5%
doing the work you want done.

You should:
1 - Use the System ThreadPool. If your work isn't I/O related (hitting SQL,
making a web service call, reading/writing to a file) this is what you want
to do. If your work is I/O centric, don't do this.

2 - Create your threads, but keep them around. When a thread is doing doing
it's work, have it go look in a "Work queue" for more work to do. This is a
good way to go in general.

This global structure is populated from a set of files at application
startup, which can be modified at run-time. There is also the option to
apply the modified files at run-time. At the time the modified files
are read into the application, I need to block access to this global
structure from the 'reader' threads. Threads do not modify this
structure.

The pattern you're looking for is a ReaderWriterLock. In my other post, I
used a Montor (which in C# looks like 'lock()'). A ReaderWriterLock is very
similar in terms of methodology though.

--
Chris Mullins, MCSD.NET, MCPD:Enterprise, MVP C#
http://www.coversant.net/blogs/cmullins


.



Relevant Pages

  • Re: Global data concurrent access ?
    ... All threads process based on data read from the ... global structure. ... apply the modified files at run-time. ... The pattern you're looking for is a ReaderWriterLock. ...
    (microsoft.public.dotnet.framework)
  • Re: Global data concurrent access ?
    ... All threads process based on data read from the ... global structure. ... apply the modified files at run-time. ... The pattern you're looking for is a ReaderWriterLock. ...
    (microsoft.public.dotnet.framework)
  • Re: Global data concurrent access ?
    ... All threads process based on data read from the ... global structure. ... apply the modified files at run-time. ... The pattern you're looking for is a ReaderWriterLock. ...
    (microsoft.public.dotnet.framework)
  • Re: Global data concurrent access ?
    ... All threads process based on data read from the ... global structure. ... apply the modified files at run-time. ... The pattern you're looking for is a ReaderWriterLock. ...
    (microsoft.public.dotnet.framework)

Loading