multithreading

Trace listener - creating memory overflow

I am using tracelistener in a multithreaded application to log message remotely, but the appllication creates memory overflow. For testing I created 10,000 threads, and tried to log messages using TraceData function. Does .Net framework create an object for every call to TraceData, which result in memory overflow? ...

PostThreadMessage returns ERROR_INVALID_THREAD_ID

I have a multi-threaded simulation running on Windows Vista. When I use PostThreadMessage to send messages between threads, I am getting ERROR_INVALID_THREAD_ID, even though I am quite certain (from stepping through the debugger) that the thread id is valid, and the thread has a message queue, since I call PeekMessage from every thread a...

Is this a thread safe way to initialize a [ThreadStatic] ?

[ThreadStatic] private static Foo _foo; public static Foo CurrentFoo { get { if (_foo == null) { _foo = new Foo(); } return _foo; } } Is the previous code thread safe? Or do we need to lock the method? ...

Performance regarding cached IEnumerable<T> implementation

[EDIT] The new Reactive Framework solves the problem outlined below, using the System.Linq.EnumerableEx.MemoizeAll() extension method. Internally, MemoizeAll() uses a System.Linq.EnumerableEx.MemoizeAllEnumerable<T> (found in the System.Interactive assembly), which is similar to my ThreadSafeCachedEnumerable<T> (sorta). Here's an awfu...

Do I need to syncronize thread access to an int

I've just written a method that is called by multiple threads simultaneously and I need to keep track of when all the threads have completed, the code uses this pattern: private void RunReport() { _reportsRunning++; try { //code to run the report } finally { _reportsRunning--; } } This is the only p...

Multi-Threaded Database Queries

So we have this ultimate fail vendor (it's a long story, but trust me here) that has created an application that has separate, but identical in design, databases that we need to query (10 of them actually). Each of these databases is for a different "location" - but it's all still information relevant to all locations. I've written some...

C# Monte Carlo Incremental Risk Calculation optimisation, random numbers, parallel execution

My current task is to optimise a Monte Carlo Simulation that calculates Capital Adequacy figures by region for a set of Obligors. It is running about 10 x too slow for where it will need to be in production and number or daily runs required. Additionally the granularity of the result figures will need to be improved down to desk possib...

Why doesn't this threaded network code work? (Java)

Code for server: http://stikked.com/view/64826511 Network Code for client: http://stikked.com/view/38974838 Basically, the client connects to the server, but beyond that, it does not work. When a message is sent, the client's System.out.println indicates that the GUI is calling the correct function. But there is no sign of the server...

Newbie Thread Question (FFTW)

I'm using the threaded version of FFTW (a FFT library) to try to speed up some code on a dual CPU machine. Here is the output of time w/ only 1 thread: 131.838u 1.979s 2:13.91 99.9% Here it is with 2 threads: 166.261u 30.392s 1:52.67 174.5% The user times and the CPU load percentages seem to indicate that it is threading pretty eff...

java how to do a sender thread

Hi all, I was told that any data going out over an output stream (i'm using tcp/ip in my case) could block. In that case, I would not want to halt the application by having to wait for data to go out. I need a model of how to do this. I need to send message objects over this stream. I am thinking I need a blocking queue that conta...

Are volatile variable 'reads' as fast as normal reads?

I know that writing to a volatile variable flushes it from the memory of all the cpus, however I want to know if reads to a volatile variable are as fast as normal reads? Can volatile variables ever be placed in the cpu cache or is it always fetched from the main memory? ...

Has anyone seen a programming language that handles threads like this?

Most of the multithreaded work I have done has been in C/C++, Python, or Delphi (Object Pascal). All on Windows. I'll use Delphi for my discussion here. Delphi has a nice class called TThread which abstracts the thread creation process. The class provides an Execute method which is the created thread's thread function. You override ...

Does one assembler instruction always execute atomically?

Today I came across this question: you have a code static int counter = 0; void worker() { for (int i = 1; i <= 10; i++) counter++; } If worker would be called from two different threads, what value will counter have after both of them are finished? I know that actually it could be anything. But my internal guts tells me...

What's the purpose of Thread.SpinWait method?

From the MSDN is not really clear its purpose. Can it be used to simulate an intensive CPU calculation test? ...

appdomains in COM interop

I have a .Net class that calls a c++ COM object which in turn calls another .Net class in COM. I've found that the two .Net classes are in seperate appdomains (which makes some trouble with log4net). Note they are in the same thread though. Why is this? Is there a way to ensure they will be in the same appdomain? ...

error pops up while accessing a file by two applications at a time.

HI all, I have a text file which is a used by two applications. Firstly a text file will be getting updated on a timely basis(say for 10 seconds) by an application built by java. These details updated by text file will be used by our application which is built in c#. But an error is thrown whenever there is a clash between the two ap...

MultiThreading and Deadlock

suggest me any real time situations in which i'm supposed to create multiple threads,and then introduce a deadlock situation.this is kind of a project!!! can u ppl help to make the application more interestin with some real time situation... ...

Quick C# threading class

Got a quick question on creating a C# thread. It needs to run every 10 minutes The worker will do work then go into sleep for another 10 minutes It can also be triggered to run immediately by calling Trigger() It can be stopped by calling Stop() I've created one with ManualResetEvent, which is set when Stop() is called. This works we...

Rendering SRS Report & Sub-Report And Multi-threading

Hello, I wrote a procedure that compiles many of our invoices using MS SQL Server Reporting Services. The procedure cycles through all the invoices for the month, loads the RDLC file, and renders the report. Note that the report also includes a subreport. The rendered report is then converted to PDF and saved on the disk. This works fi...

how to get string value from thread

I am running a thread in C#. I have web form. I declared public string attribute in my web form. (e.g. string myVal) Then I called thread and assign value into myVal. It assign values in it. But when I exit from thread code, myVal become null. Is there anyway to keep myVal value. public string myVal; protected void Page_Load(object se...