multithreading

C# Multi-Threading - What method to use?

My goal is to write a program that handles an arbitrary number of tasks based on given user input. Let's say the # of tasks are 1000 in this case. Now, I'd like to be able to have a dynamic number of threads that are spawned and start handling the tasks one by one. I would assume I need to use a "synchronous" method, as opposed to a...

Threadpool in IIS context

Hi. I have a general question about System.Threading.Threadpool when run in a webapplication on IIS. Say we have 2 requests execute at once, and we fire up a couple of threads through the ThreadPool.QueueUserWorkItem method. Will the two requests share the ThreadPool, or will the calls to the ThreadPool from the two requests operate in...

Asynchronous Multicast Delegates

I've been doing some work lately on a project that makes extensive use of events. One of the things that I need to do is asynchronously call multiple event handlers on a multicast delegate. I thought the trick would be to call BeginInvoke on each item from GetInvocationList, but it appears as though BeginInvoke doesn't exist there. Is t...

Lock-Free, Wait-Free and Wait-freedom algorithms for non-blocking multi-thread synchronization.

In multi thread programming we can find different terms for data transfer synchronization between two or more threads/tasks. When exactly we can say that some algorithm is: 1)Lock-Free 2)Wait-Free 3)Wait-Freedom I understand what means Lock-free but when we can say that some synchronization algorithm is Wait-Free or Wait-Freedom? I ...

Are BinaryFormatter Serialize and Deserialize thread safe?

Referencing this answer to a question. Can this be rewritten as: private static BinaryFormatter formatter = new BinaryFormatter(); public static T DeepClone<T>(this T a) { using(MemoryStream stream = new MemoryStream()) { formatter.Serialize(stream, a); stream.Position = 0; return (T)formatter.Deserialize(stream)...

Safely echoing MIDI data in C#

As a side project, I am implementing a MIDI matrix to interconnect a number of MIDI keyboards with sound sources. The key requirement here is to echo MIDI data received on an input port to a selected output port. Having created the necessary P/Invoke declarations & wrappers, I notice that the Win32 MIDI documentation for MidiInProc state...

Multithreaded use of Core Data (NSOperationQueue and NSManagedObjectContext)

In Apple's Core Data documentation for Multi-Threading with Core Data, they list the preferred method for thread safety as using a seperate NSManagedObjectContext per thread, with a shared NSPersistentStoreCoordinator. If I have a number of NSOperations running one after the other on an NSOperationQueue, will there be a large overhead c...

Flow control in threading.Thread

I Have run into a few examples of managing threads with the threading module (using Python 2.6). What I am trying to understand is how is this example calling the "run" method and where. I do not see it anywhere. The ThreadUrl class gets instantiated in the main() function as "t" and this is where I would normally expect the code to sta...

How to access MySQL from multiple threads concurrently

We're doing a small benchmark of MySQL where we want to see how it performs for our data. Part of that test is to see how it works when multiple concurrent threads hammers the server with various queries. The MySQL documentation (5.0) isn't really clear about multi threaded clients. I should point out that I do link against the thread ...

How to get the cpu usage per thread on Mac OSX

I am looking for an OS level API to account for cycles consumed by a specific thread in OSX. This is similar to this question (and answer) but in OSX. ...

Reading Critical Section Data using pthreads

I have a multi-threaded application, I'm using pthreads with the pthread_mutex_lock function. The only data I need to protect is in one data structure. Is it safe if I apply the lock only when I write to the data structure? Or should I apply the lock whenever I read or write? I found a question similar to this, but it was for Windows...

Spinlocks, How Much Useful Are They?

How often do you find yourself actually using spinlocks in your code? How common is it to come across a situation where using a busy loop actually outperforms the usage of locks? Personally, when I write some sort of code that requires thread safety, I tend to benchmark it with different synchronization primitives, and as far as it goes,...

Can an ASP.NET worker thread handle multiple requests at once?

I know that ASP.NET will execute a request on a single thread from a pool. Is the inverse true? Will a single ASP.NET request exclusively hold a worker thread until the request completes, or will ASP.NET re-use the same thread between multiple concurrent requests? ...

Creating a new thread (C, Windows)

OK, I'm a bit confused here. The following code works: HANDLE CreateSideThread() { DWORD dwGenericThread; HANDLE hThread1 = CreateThread(NULL, 0, CallBackFunc, NULL, 0, &dwGenericThread); return hThread1; } int main() { HANDLE Thread1; Thread1 = CreateSideThread(); WaitForSingleObject(hThread1, INFINITE); ...

How to prevent a new WPF form from stealing focus?

I have written a simple MSN-style program that will send and retrieve messages using WCF. The main form contains a Textbox to type in the message to be sent. In the background the application polls the server every few seconds for new messages. When a new message is received a new window is opened to display it. This has to be done on th...

WPF Take screenshot from other thread than main thread

Hi, I have a thread that listens for commands to my WPF application. If the WPF Application gets a command to take a screenshot the task is handed over to a "screenshotService". I found som code to take the screenshot somewhere on the interweb, seems to work, but i havent thought it through....i cannot take this screenshot from another t...

Is it safe to issue blocking write() calls on the same TCP socket from multiple threads?

Let's say I have two threads, T1 and T2. Thread T1 makes a blocking write() call on a TCP socket S to send a large buffer of bytes B1. The buffer of bytes B1 is so large that (a) the write call blocks and (b) TCP has to use multiple segments to send the buffer. Thread T2 also makes a blocking write() call on the same TCP socket S to se...

Testing performance of parallel programs on a single core machine

I would like to start playing with concurrency in the programs I write (mostly for fun), but I don't own a multi-core system and can't afford one any time soon. I run linux. Is there a way to, for example with a Virtual Machine, compare the performance of a multi-threaded implementation of a program with a single-threaded version, withou...

WinForms TextBox : how to reformat asynchronously, without firing TextChanged event

This is a followup to WinForms RichTextBox: how to perform a formatting on TextChanged? I have a Winforms app with a RichTextBox, the app auto-highlights the content of said box. Because the formatting can take a long time for a large document, 10 seconds or more, I've set up a BackgroundWorker to do the re-formatting of a RichTextBox. ...

shared resource between child thread & parent thread

hi all, I have met a problem with asp.net. Textbox can't be updated. "Main Thread" runs on Page_load. It calls child thread, which change the text of textbox, recursively. Here is my code serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); //Assign the any IP of the machine and list...