multithreading

Create element in background thread an then add to main-interface.

Hello, i have a problem with threading in WPF. I want to have created a complex user interface and then i want to add it to my main-window. While this complex user interface is creating i want to show a progress bar in my main window. I think this only could be made with threads. But there is a problem. The created element can't be adde...

Best way to configure a Threadpool for a Java RIA client app

Hi all, I've a Java client which accesses our server side over HTTP making several small requests to load each new page of data. We maintain a thread pool to handle all non UI processing, so any background client side tasks and any tasks which want to make a connection to the server. I've been looking into some performance issues and I'...

Why there are not any real lightweight threads for python?

I'm new to Python and seems that the multiprocessing and threads module are not very interesting and suffer from the same problems such as threads in Perl. Is there a technical reason why the interpreter can't use lightweight threads such as posix threads to make an efficient thread implementation that really runs on several cores? ...

multi-thread access MySQL error

I have written a simple multi-threaded C program to access MySQL,it works fine except when i add usleep() or sleep() function in each thread function. i created two pthreads in the main method, int main(){ mysql_library_init(0,NULL,NULL); printf("Hello world!\n"); init_pool(&p,100); pthread_t producer; ...

Java long running task Thread interrupt vs cancel flag

I have a long running task, something like: public void myCancellableTask() { while ( someCondition ) { checkIfCancelRequested(); doSomeWork(); } } The task can be cancelled (a cancel is requested and checkIfCancelRequested() checks the cancel flag). Generally when I write cancellable loops like this, I use a fl...

Am I using ThreadPool correctly & performance...

I have a .net windows service that works it's way through a queue of items and does some research on each one. I'm trying to change it to a threaded model so that batches items can be researched concurrently rather than doing each item sequentially. I know this isn't the perfect solution (it currently has to wait for the slowest item t...

What's the best way to have multiple threads doing work, and waiting for all of them to complete?

I'm writing a simple app (for my wife no less :-P ) that does some image manipulation (resizing, timestamping etc) for a potentially large batch of images. So I'm writing a library that can do this both synchronously and asynchronously. I decided to use the Event-based Asynchronous Pattern. When using this pattern, you need to raise an e...

Device Driver DLL Blocking vs NonBlocking?

My company makes a product that connect to the PC via USB. I am writing a DLL driver, using Visual C#, for this product so that anyone who wants to write a program that can control or device can do so. Some of the operations that the driver will execute take several seconds for the device to complete (for example moving the motor in th...

Stopping an MFC thread

I understand the problem with just killing the thread directly (via AfxEndThread or other means), and I've seen the examples using CEvent objects to signal the thread and then having the thread clean itself up. The problem I have is that using CEvent to signal the thread seems to require a loop where you check to see if the thread is sig...

How do I make an eventhandler run asynchronously?

I am writing a Visual C# program that executes a continuous loop of operations on a secondary thread. Occasionally when that thread finishes a task I want it to trigger an eventhandler. My program does that but the when the event handler is triggered, the secondary thread waits until the event handler is finished before continuing the th...

reliably reproducing db contention

we experience with some regularity contention on a database table, and would like to evaluate a number of different options for resolving this issue. in order to do so, i need to reproduce in a test case, contention on a table (any table) with repeatable reliability. the approach i'm considering would be to reverse the semantics of a l...

How can I get a number to count forward on the screen in WPF?

All I wanted to do was show my 5-year-old daughter how a number can count forward on the screen. This waits 135 seconds and then displays "135". What do I have to change so that it displays the number as it counts? XAML: <Window x:Class="TestCount234.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" x...

How can I stop a thread in C# ?

I've created a Client-Server application, and on the Server I want to have the oportunity to stop the server and then start it again. The problem is that I can't stop the Thread that listen for Tcp Connections. How can I close a Thread in C#? Thanks. private void KeepServer(){ while (this.connected) { tcpClient = tls....

How to make a Windows Service terminate when one of its sub-threads terminate

in the ServiceStart() call of a windows service, I create a thread and start it. Thread1 = New TThread1(false) In the Execute procedure of the subthread, there is a loop that runs forever and does that the service is supposed to do. The problem is that when I get an error in this thread, I want to terminate the thread, and stop the ser...

C++ Builder - Spawn TThreads On the Fly

I'm looking for the ability to spawn a thread or function so that it returns immediately to the calling line and continue on with the program but continues with the thread work. For instance, if you call Form.ShowDialog(), it will create a modeless form that has its own UI thread. Is there a way to do this (no form) without having to ...

Critical Sections that Spin on Posix?

The Windows API provides critical sections in which a waiting thread will spin a limited amount of times before context switching, but only on a multiprocessor system. These are implemented using InitializeCriticalSectionAndSpinCount. (See http://msdn.microsoft.com/en-us/library/ms682530.aspx.) This is efficient when you have a critic...

Changing UI elements from another thread in .NET

I don't get it. If I want to change the text on a button from a thread other than the UI thread in Visual Basic .NET, I need to use a delegate, and do something along the lines of Private Delegate Sub SetTextDelegate(ByVal TheText As String) Private Sub delSetText(ByVal TheText As String) Button1.Text = TheText End Sub Private...

ShowWindow and messageloop

I'm using ShowWindow from user32.dll to show messenger style popups ( always on top, doesn't steal focus ), but I can't get them to respond. It seems that my new form is missing a messageloop, and therefore cannot draw it's controls or react to input. I've tried to create the form in a backgroundworker, but that doesn't seem to help (fo...

Does the JVM or the underlying OS handle thread state changes

When I create a multi-threaded program and I use methods such as Wait or Signal to control threads among other things, does JVM control all the thread state changes or does the underlying OS have anything to do with it. ...

looking for the NAME of a specific kind of concurrency problems

You have the following scenario: //Two threads, using shared data shared data = 2 Thread1: reads shared data Thread2: reads shared data Thread1: shared data = read value + 1 Thread2: shared data = read value + 1 result: shared data = 3 //Should have been 4 if not for this problem. I don't want a solution for the problem,...