multithreading

Concurrent read access on an int[] array: Is it safe? Is it fast?

On a quad-core machine, I am considering the parallelization of C#/.NET algorithm which involves having multiple threads reading the small int[] array concurrently. So far, it seems to be working rather well, but I am not sure where it is specified that concurrent reads on an array are thread-safe in .NET. Any pointers? Then, I am also ...

Calling a method on thread termination

I am writing a java program which tracks as threads are created in a program and is then supposed to perform some work as each Thread terminates. I dont see any 'thread termination hooks' out there in the javadoc. Currently the only way I can think of to achieve my requirement is to hold on to the thread objects and query its 'state' a...

How to share data between model and view?

I'm currently working on redesigning an application which is building a model from input data, and displaying that data to the user. The current system has a thread for building the model, a thread for building a visualization of the model, and a thread which displays the visualization. The problem I have is that pointers are passed betw...

Can I force cache coherency on a multicore x86 CPU?

The other week, I wrote a little thread class and a one-way message pipe to allow communication between threads (two pipes per thread, obviously, for bidirectional communication). Everything worked fine on my Athlon 64 X2, but I was wondering if I'd run into any problems if both threads were looking at the same variable and the local ca...

Proper way to clean up a permanent thread in C#

I have an object, a Timeline, that encapsulates a thread. Events can be scheduled on the timeline; the thread will wait until it is time to execute any event, execute it, and go back to sleep (for either (a) the time it takes to get to the next event or (b) indefinitely if there are no more events). The sleeping is handled with a WaitEv...

pthreads - how to parallelize a job

I need to parallelize a simple password cracker, for using it on a n-processor system. My idea is to create n threads and to feed them more and more job as they finish. What is the best way to know when a thread has finished? A mutex? Isn't expensive checking this mutex constantly while other threads are running? ...

Lightweight Thread Pool Libraries in .NET

I'm looking for a thread pool library in .NET I should able to push about 100.000 tasks, therefore should provide support for "blocking" . (obviously I can't push so many tasks at once, so should support some blocking while adding new tasks, and should block the thread until a new slot is available) Not overly complicated Not so expen...

Does MessageBox.Show() automatically marshall to the UI Thread ?

Hi, I launch a thread via ThreadPool.QueueUserWorkItem which has a messagebox dialogue in it: System.Windows.Forms.DialogResult dr = System.Windows.Forms.MessageBox.Show("would you like to download upgrade in background? ..", "Upgrade Available", MessageBoxButtons.YesNo); It seems to work fine however I am a little suspicious after so...

Do ASMX or WCF Proxy clients use IO completion ports?

I'm in the middle of performance testing a critical section of my project, when I notice a whole lot of extra threads being used to to perform WaitOrTimerCallback operations. On closer inspection I can see that these are being spawned by my ASMX client proxy class for operations on a remote server. I was under the impression that t...

Multithreading in C#: How can I pass a function name to another function to start a new thread?

I am using multithreading in my C# code as follow: Thread startThread; public void NewThread() { ThreadStart starter = delegate { foo(); }; startThread = new Thread(starter); startThread.Start(); } private void foo() { //do some work } And then in my application I call NewThread()to run the new thread. But now I am havi...

Is thread-local storage persisted between backgroundworker invocations?

Are backgroundworker threads re-used? Specifically, if I set a named data slot (thread-local storage) during the DoWork() method of a backgroundworker, will the value of that data slot persist, potentially to be found be some other thread at a later time? I wouldn't have thought so, but I have this bug... EDIT: This blog post suggests...

How can I manage which items are in the ThreadPool?

I have a windows service that runs a method when the services main Timer elapses (OnElapse). The OnElapse method gets a list of .xml files to process. Each xml file is inserted into a ThreadPool. I want to make sure I don't insert 2 XML's with the same name into the ThreadPool. How can I manage which items are in the ThreadPool? I ba...

How will a lock respond to a race condition?

How long will a thread wait for a race condition in the following scenario? A file is added to a collection: lock(mylock) { // add to collection } It is then removed from the collection in a similiar manner. If a thread is trying to add to the collection while the service is removing it from the collection, who wins? Or is...

Best practices for multithreaded processing of database records

I have a single process that queries a table for records where PROCESS_IND = 'N', does some processing, and then updates the PROCESS_IND to 'Y'. I'd like to allow for multiple instances of this process to run, but don't know what the best practices are for avoiding concurrency problems. Where should I start? ...

Why does Thread.Sleep(0) fix my problems, and how to avoid it?

I'm working on a client server application. At certain times, on certain machines, when there's more than 5 clients requesting data, it seems to reach a deadlock. If I step in to debug the problem, then the program appears to be processing. Simply setting a break point where I know the program is executing, and causing it to hit the b...

Achieving Thread-Safety

Question How can I make sure my application is thread-safe? Are their any common practices, testing methods, things to avoid, things to look for? Background I'm currently developing a server application that performs a number of background tasks in different threads and communicates with clients using Indy (using another bunch of automa...

Dividing loop iterations among threads

I recently wrote a small number-crunching program that basically loops over an N-dimensional grid and performs some calculation at each point. for (int i1 = 0; i1 < N; i1++) for (int i2 = 0; i2 < N; i2++) for (int i3 = 0; i3 < N; i3++) for (int i4 = 0; i4 < N; i4++) histogram[bin_index(i1, i2, i3, i4)] += 1; // see b...

dynamic proxies with jmx can cause thread leaks?

I have a problem in Java where I set up a dynamic proxy with a JMX interface, pass this on to another component which then makes calls to the proxy object. When I do this, the application leaks two threads for each call, threads which never seem to time out and keep building up until the application runs out of memory. The threads appe...

Single socket multiple clients architecture

I have to maintain a single persistent socket connection to a payment gateway and use it to send financial messages and receive confirmation for the same. My application will be then used by various clients and so I need to devise a way to handle them concurrently and handle issues such as timeouts and retries etc. Right now, my main ...

Multithreaded job queue manager

I need to manage CPU-heavy multitaskable jobs in an interactive application. Just as background, my specific application is an engineering design interface. As a user tweaks different parameters and options to a model, multiple simulations are run in the background and results displayed as they complete, likely even as the user is still...