multithreading

ThreadA and ThreadB both call WaitOne() in that order on the same AutoResetEvent - when the event is set, why does ThreadB get released instead of ThreadA?

I ran a test to find out what happens when you set an AutoResetEvent on which mutiple threads are waiting: private static void Test() { // two threads - waiting for the same autoreset event // start it unset i.e. closed i.e. anything calling WaitOne() will block AutoResetEvent autoEvent = new AutoResetEve...

Is there a way I can make two reads atomic?

I'm running into a situation where I need the atomic sum of two values in memory. The code I inherited goes like this: int a = *MemoryLocationOne; memory_fence(); int b = *MemoryLocationTwo; return (a + b) == 0; The individual reads of a and b are atomic, and all writes elsewhere in the code to these two memory locations are also loc...

daemon threads in an app container

I read in a post to the Smack forum recently that Starting daemon threads in a Java EE server is a big no no Basically Smack's XMPPConnection starts one daemon thread to monitor incoming data & another to send outgoing data from/to the jabber server respectively. Is it reasonable to use daemon threads to listen for write/reads in ...

Why use the APM instead of using a separate thread?

If I want to read or write a file I could use stream.BeginRead and stream.EndRead, but that requires callbacks and a LOT of ugly, complicated code using the asynchronous programming model. Why would I want to use these asynchronous IO methods (that use the .NET threadpool behind the scenes) than write the same code in a synchronous styl...

pthread returns 251

pthread_create returns the value 251 without creating the thread. Does anyone know what the problem is? Please help. The machine is a HP-UX. I'm new to multi-threading. #include <stdio.h> #include <stdlib.h> #include <pthread.h> void *print_message_function( void *ptr ); main() { pthread_t thread1, threa...

Followup: Multiprocessing or Multithreading for Python simulation software

Hello folks, this is a follow up to this. (You don't have to read all the answers, just the question) People explained to me the difference between processes and threads. On the one hand, I wanted processes so I could fully exploit all core of the CPU, on the other hand, passing information between processes was less than ideal, and I d...

ThreadPool.QueueUserWorkItem with a lambda expression and anonymous method.

Passing two parameters to a new thread on the threadpool can sometimes be complicated, but it appears that with lambda expressions and anonymous methods, I can do this: public class TestClass { public void DoWork(string s1, string s2) { Console.WriteLine(s1); Console.WriteLine(s2); } } try { TestClass te...

Binding, threads and winforms

How do I bind a ProgressBar to a property of a class updated in another thread? The following code example shows my first naive attempt. It doesn't work because I get runtime errors about cross thread communication. I think I need to use Invoke in some way, but I'm not sure how to do it with the Binding class. using System; using Syste...

Is there an advantage of the operating system understanding the characteristics of how a thread may be used?

Is there an advantage of the operating system understanding the characteristics of how a thread may be used? For example, what if there were a way in Java when creating a new thread to indicate that it would be used for intensive CPU calculations vs will block for I/O. Wouldn't thread scheduling improve if this were a capability? ...

Kernel Scheduling for 1024 CPUs

Azul Systems has an appliance that supports thousands of cache coherent CPUs. I would love insight into what changes would need to occur to an operating system in order to schedule thousands of simultaneously running threads. ...

How to handle starting/stopping API interface that may take a long time to start

I have an application that needs to work with a vendor-supplied API to do Screen Pops when a call is routed to the user's extension. Another developer worked on getting the API to work and delivered a prototype wrapper class that isn't quite right, and I'm trying to get it right. Because this API can block for several minutes before re...

VBA + Threads

How can I create a process running on a separate thread in MS Access VBA? I would like to create a process that will just sit and wait for a message. ...

Question about app with multiple threads in a few CPU-machine

Given a machine with 1 CPU and a lot of RAM. Besides other kinds of applications (web server etc.), there are 2 other server applications running on that machine doing the exact same kind of processing although one uses 10 threads and the other users 1 thread. Assume the processing logic for each request is 100% CPU-bound and typically...

Is it safe to call a dll function from multiple threads in a single application?

I am writing a server application in Delphi 2009 that implements several types of authentication. Each authentication method is stored in a separate dll. The first time an authentication method is used the appropriate dll is loaded. The dll is only released when the application closes. Is it safe to access the dlls without any form of s...

Python: Locks from `threading` and `multiprocessing` interchangable?

Are the locks from the threading module interchangeable with those from the multiprocessing module? ...

Update Counter on Thread in .NET

I am writing a server program that does some basic threading. It needs to update some UI controls and I learned how to use delegates such that everything is thread safe. For example, here's my delegate that allows me to update a TextBox control from a thread: Private Delegate Sub AddMessageToTXTDelegate(ByVal lst As TextBox, ByVal str...

Ensuring methods are only ever executed by the main thread.

I have an objective-c class whose methods I only ever want to be called from the main thread. I could achieve this by adding something like this to each selector: - (void) exampleSelector: (id) param { if (![NSThread isMainThread]) { [self peformSelectorOnMainThread:@selector(exampleSelector:) withObject:param waitUntilDone...

Dynamic processes in Python

I have a question concerning Python multiprocessing. I am trying to take a dataset, break into chunks, and pass those chunks to concurrently running processes. I need to transform large tables of data using simple calculations (eg. electrical resistance -> temperature for a thermistor). The code listed below almost works as desired, but...

low level programming: How does the OS start a new thread/process?

Whenever the bootloader loads the operating system there is presumably only ONE program flow active, right? This would mean, one processor holds the instruction pointer and executes the commands it founds at the position the EIP register points to. At which point and how does the system start to exploit more processes and/or threads (no ...

Capture Console Output of a Specific Thread in Java

I realize there are similar questions on SO, but they don't quite solve my problem. I would like a method that, given a Class object, will invoke the "main" method, that is to say, public static void main, on that Class (if it exists) and capture the console output of that main method. The class doing the invocation is a non-daemon thr...