multithreading

Primitive synchronization primitives -- safe?

On constrained devices, I often find myself "faking" locks between 2 threads with 2 bools. Each is only read by one thread, and only written by the other. Here's what I mean: bool quitted = false, paused = false; bool should_quit = false, should_pause = false; void downloader_thread() { quitted = false; while(!should_quit) { ...

Processing messages is too slow, resulting in a jerky, unresponsive UI - how can I use multiple threads to alleviate this?

I'm having trouble keeping my app responsive to user actions. Therefore, I'd like to split message processing between multiple threads. Can I simply create several threads, reading from the same message queue in all of them, and letting which ever one is able process each message? If so, how can this be accomplished? If not, can you...

Is there no simple way to set WPF StatusBar text?

I want to set the Text of a TextBlock in my StatusBar before making the user wait for a short moment while my program does a little bit of work. Aparently, instead of doing a nice little function like this (which does not work): Function Load(ByVal Id As Guid) As Thing Cursor = Cursors.Wait TextBlockStatus.Text = "Loading..." ...

How good is the JVM at parallel processing? When should I create my own Threads and Runnables? Why might threads interfere?

I have a Java program that runs many small simulations. It runs a genetic algorithm, where each fitness function is a simulation using parameters on each chromosome. Each one takes maybe 10 or so seconds if run by itself, and I want to run a pretty big population size (say 100?). I can't start the next round of simulations until the prev...

Control.Invoke with input Parameters

From what I've found in C#, the Control.Invoke method requires that you use a delegate with no input parameters. Is there any way around this? I would like to invoke a method to update the UI from another thread and pass to string parameters to it. ...

What is the exception thrown in a running .NET thread when Windows shuts down?

The exact exception message would be helpful, too. Thanks. ...

OutOfMemoryError - why can a waiting Thread not be garbage collected?

This simple sample code demonstrates the problem. I create an ArrayBlockingQueue, and a thread that waits for data on this queue using take(). After the loop is over, in theory both the queue and the thread can be garbage collected, but in practice I soon get an OutOfMemoryError. What is preventing this to be GC'd, and how can this be fi...

WinForms window created on worker thread not receiving all expected messages

I am playing back audio in C# using the waveOut functions with the callback method where messages are sent back to a window handle. I am creating a Windows Form with an overidden WndProc function to listen for the MM_WOM_DONE messages. result = WaveInterop.waveOutOpen(out hWaveOut, devNumber, waveStream.WaveFormat, waveOutWindow.Handle...

Can an asynchronous HttpHandler's request be interrupted without an exception?

We are using an asynchronous HttpHandler in ASP.NET 3.5 under IIS 6, and in our code we're wanting to perform an external API call if we're not under too much load. We've defined "too much load" meaning that if we have more than X requests hitting this API at the same time, we'll just skip calling the API. To accomplish this, we've wrap...

How to maintain a list of functions in C++/STL ?

Hi, Before asking you my question directly, I'm going to describe the nature of my prolem. I'm coding a 2D simulation using C++/OpenGL with the GLFW library. And I need to manage a lot of threads properly. In GLFW we have to call the function: thread = glfwCreateThread(ThreadFunc, NULL); (the first parameter is the function that'll exec...

C# Events and Thread Safety

I frequently hear/read the following advice: Always make a copy of an event before you check it for null and fire it. This will eliminate a potential problem with threading where the event becomes null at the location right between where you check for null and where you fire the event: // Copy the event delegate before checking/calling...

Multi threading using NXT

At my robotics club we are trying to get the multi-threading capability to work on LEGO Mindstorms NXT, but it seems that the threads are interfering with each other and causing the program to stop entirely. Does anyone know how to correctly implement multi-threading on the NXT visual programming environment. ...

[C#] Thread-safe Form.Show

I'm writing a Toast that needs to be thread-safe as it's being used to report the status of asynchronous socket input. I've tried to make it thread-safe but the toasts are still locking up. public static void Show( string message ) { Toast toast = new Toast( message ); toast.ShowAction(); } private delegate ...

IBM Websphere on Windows- OutOfMemoryError: Failed to create a thread

I have a J2EE application running on an IBM Websphere Application Server on a Windows Operating System. Occasionally I see an OutOfMemoryError Exception with the following information in the javacore file. 1TISIGINFO Dump Event "systhrow" (00040000) Detail "java/lang/OutOfMemoryError":"Failed to create a thread: retVal -1073741830...

Forcing code execution on main thread.

How can I force a section of code to be executed on my main thread? This is why I'd like to know: I have a custom created message box that at times gets shown from a thread that is not the main thread. However, when the message box constructor is called I get an InvalidOperationException saying "The calling thread must be STA, because...

How does a threading.Thread yield the rest of its quantum in Python?

I've got a thread that's polling a piece of hardware. while not hardware_is_ready(): pass process_data_from_hardware() But there are other threads (and processes!) that might have things to do. If so, I don't want to burn up cpu checking the hardware every other instruction. It's been a while since I've dealt with threading, and...

Do i need a lock on a list? C#

I filled several list<> with default values, stuck them into a struct then pass the struct into several threads. Each thread has a different range so thread 1 would access list[0 to 199] thread 2 would access [200 - 400] etc. Would i need a lock? and when do i need it? i can access the list with my multiple threads w/o using a lock. But...

Pthreads as a standard solution for simultaneous console input in UNIX?

I got an assessment to write a simple chat client for Linux using ncurses. The chat has two windows: one displays what the other client says, the other handles user input. What confuses me here is how to handle data that constantly comes from the socket and waits for the user's input at the same time. The only one solution that comes in...

Duplicate WCF service calls being saved in database

We have a C# WCF service (3.0) that takes in data and then make another web service call to a third party with that same data. Before the third party call, the entry data is saved as a record in a database, and then updated with response data from the thrid party web service. We have start doing some Load/Stress testing, and noticed th...

Calling a function with different number of threads passed to the application

I have a function which needs to be invoked with a different number of threads each time (am doing some performance calculation, so need to know when the performance starts deteriorating). Example is given below: getTime() { return 0; } int main() { boost::threadpool::thread_pool<> threads(nThreads); for(int j = 0; j <= nL...