multithreading

C++ Thread, shared data

I have an application where 2 threads are running... Is there any certanty that when I change a global variable from one thread, the other will notice this change? I don't have any syncronization or Mutual exclusion system in place... but should this code work all the time (imagine a global bool named dataUpdated): Thread 1: while(1) ...

How do you ensure multiple threads can safely access a class field?

When a class field is accessed via a getter method by multiple threads, how do you maintain thread safety? Is the synchronized keyword sufficient? Is this safe: public class SomeClass { private int val; public synchronized int getVal() { return val; } private void setVal(int val) { this.val = val; ...

Will it be faster to use several threads to update the same database?

I wrote a Java program to add and retrieve data from an MS Access. At present it goes sequentially through ~200K insert queries in ~3 minutes, which I think is slow. I plan to rewrite it using threads with 3-4 threads handling different parts of the hundred thousands records. I have a compound question: Will this help speed up the prog...

Problem accessing file from different thread in Asp.net

I have a process in a website (Asp.net 3.5 using Linq-to-Sql for data access) that needs to work as follows: Upload file Record and save info regarding file to database Import data from file into database Redirect to different page When run sequentially like this, everything works fine. However, since the files being imported can be ...

How to update components in different threads? .NET CF

Hi, I´m programming a .NET Compact Framework application which shows maps on a PDA. I´ve created an ad hoc component that paints it´s own piece of the whole map, using several of this components the big picture is composed. I did it this way to avoid the latency of painting the whole map in a single step. What I would like to do know i...

Sleep a thread until an event is attended in another thread

I have two threads in an Android application, one is the view thread, and the other a worker thread. What i want to do is to sleep the worker thread until the view thread terminates the handling of the onDraw method. How i can do this? is there a wait for a signal or something? ...

.NET: How to have background thread signal main thread data is available?

What is the proper technique to have ThreadA signal ThreadB of some event, without having ThreadB sit blocked waiting for an event to happen? i have a background thread that will be filling a shared List<T>. i'm trying to find a way to asynchronously signal the "main" thread that there is data available to be picked up. i considered ...

.NET: How to wait for a BackgroundWorker to cancel?

Consider a hypothetical method of an object that does stuff for you: public class DoesStuff { BackgroundWorker _worker = new BackgroundWorker(); ... public void CancelDoingStuff() { _worker.CancelAsync(); //todo: Figure out a way to wait for it to be cancelled } } How can one wait for a BackgroundWorker to...

How to make my code run on multiple cores?

I have built an application in C# that I would like to be optimized for multiple cores. I have some threads, should I do more? Updated for more detail C# 2.0 Run on Windows Vista and Windows Server 2003 Updated again This code is running as a service I do not want to have the complete code... my goal here is to get your experience...

Intra-process coordination in mod_perl under the worker MPM

I need to do some simple timezone calculation in mod_perl. DateTime isn't an option. What I need to do is easily accomplished by setting $ENV{TZ} and using localtime and POSIX::mktime, but under a threaded MPM, I'd need to make sure only one thread at a time was mucking with the environment. (I'm not concerned about other uses of loca...

Are Mutexes needed in javascript?

I have seen this link: Implementing Mutual Exclusion in JavaScript. On the other hand, I have read that there are no threads in javascript, but what exactly does that mean? When events occur, where in the code can they interrupt? And if there are no threads in JS, do I need to use mutexes in JS or not? Specifically, I am wondering ab...

How to implement simple threading in Java

I'm looking for the simplest, most straightforward way to implement the following: The main program instantiates worker threads to do a task. Only n tasks can be running at once. When n is reached, no more workers are started until the count of running threads drops back below n. ...

Managing ThreadPool starvation within a multithreaded work queue processor?

I am investigating the design of a work queue processor where the QueueProcessor retrieves a Command Pattern object from the Queue and executes it in a new thread. I am trying to get my head around a potential Queue lockup scenario where nested Commands may result in a deadlock. E.G. A FooCommand object is placed onto the queue which ...

Weird Exception while using DataGridView and possibly Multi-Threads

I followed google to this MSDN forum thread. The last answer was and I qoute : "Using threads? Don't" Does someone knows a walk around? As far as I can tell, I'm playing the cards well. I'm using BeginInvoke inorder to populate the data source inside the UI thread. More details : I've got a background thread that make queries to a S...

Could you explain STA and MTA?

I'm having trouble understanding STA and MTA. If you could explain it in your own words that would be great. Also what are Apartment threads and do they pertain only to COM? If so why? ...

Java Threads priority in Linux

I have a multi thread application built on Java and I need to set different priorities to this threads. In windows it works fine, a bigger value (priority) gets more CPU time just like it was supposed. On Linux, I cant find a logical answer to how it is working. Looked online, but can't seem to find a definitive answer on how its worki...

Debugging with Events in Windows

If I create an event using CreateEvent in Windows, how can I check if that event is signaled or not using the debugger in Visual Studio? CreateEvent returns back a Handle, which doesn't give me access to much information. Before I call WaitForSingleObject(...), I want to check to see if the event is signaled before I step into the func...

Windows Forms Threading and Events - most efficient way to hand off events?

My form receives asynchronous callbacks from another object on random worker threads. I have been passing the data to the main thread (where it can be used to update onscreen controls) using delegates as shown below. Performance is dreadful -- once I reach 500 updates per second, the program completely locks up. My GUI processing itse...

How many threads should I use in my Java program?

I recently inherited a small Java program that takes information from a large database, does some processing and produces a detailed image regarding the information. The original author wrote the code using a single thread, then later modified it to allow it to use multiple threads. In the code he defines a constant; // number of thr...

.Net Multithreading: SQL ConnectionPool

In a VB.Net Windows Service I'm currently pooling units of work with: ThreadPool.QueueUserWorkItem(operation, nextQueueID) In each unit of work (or thread I'll use for ease of understanding), it will make a couple MSSQL operations like so: Using sqlcmd As New SqlCommand("", New SqlConnection(ConnString)) With sqlcmd ...