multithreading

Question about thread synchronisation

hi all, i have a question about thread situation. Suppose i have 3 threads :producer,helper and consumer. the producer thread is in running state(and other two are in waiting state)and when its done it calls invoke,but the problem it has to invoke only helper thread not consumer,then how it can make sure that after it releases resource...

C#.Net - How to cancel a BackgroundWorker pulling data from a WebService

Hi all, I've got the following code: void ReferenceManager_DoWork(object sender, DoWorkEventArgs e) { try { // Get the raw data byte[] data = this.GetData(IvdSession.Instance.Company.Description, IvdSession.Instance.Company.Password); // Deserialize the list List<T> deseriaizedList = null; ...

C# working with singleton from two different threads

I am using the singleton pattern in a wpf app, but having doubts about how to make it work with multiple threads. I have a class called Monitor which maintains a list of "settings" to watch, for different "devices". Outline shown below. On my main thread I am doing Monitor.getMonitor.register(watchlist) or Monitor.getMonitor.unregist...

Are Synchronized Methods Slower In Single Threaded Applications?

I've been debating this to myself for the last few minutes, and I'm seeing reasons for both yes and no. This stemmed from looking at the answers to Java HashMap vs. Hashtable and seeing several people say Hashtable is in fact slower. It seems to me that a synchronized method should act absolutely no different than its unsynchronized co...

Java thread running on which processor?

Is there a way to find out which processor (either on a single system or mutliple systems) your thread is running on, using Java native threads? If not, is there any library which could help? ...

"Cross-thread operation not valid" exception on inner controls

I've been struggling with this for quite a while: I have a function designed to add control to a panel with cross-thread handling, the problem is that though the panel and the control are in "InvokeRequired=false" - I get an exception telling me that one of the controls inner controls are accessed from a thread other than the thread it w...

Speeding up straggling idempotent tasks

I'm running multiple idempotent tasks to gather one batch of data. I found out that many times the computation is delayed significantly due to a couple of tasks out of a hundred. What I'd like is a way of watching these tasks and launching the stragglers again if they are significantly delayed. Is there a standard library or idiom for ...

Pub/Sub architecture

Hi, I try to write a pub/sub system ( client and server side ) , where client receives regular updates ( like heartbeat, message control ) and can issue command to server ( subscribe to some source , .... ). What would be a good way to do that? I have already a server implementing a threadpool to manage incoming client connection. ...

WPF Dispatcher and Running it in background

I tried to wrap the dispatcher in a thread. But the result is not what i expect. How can i solve that problem? public void Start() { ThreadStart ts = inner; Thread wrapper = new Thread(ts); wrapper.Start(); } private void inner() { _Runner.Dispatcher.Invoke(_Runner.Action, DispatcherP...

How do I pick the best number of threads for hyptherthreading/multicore?

I have some embarrassingly-parallelizable work in a .NET 3.5 console app and I want to take advantage of hyperthreading and multi-core processors. How do I pick the best number of worker threads to utilize either of these the best on an arbitrary system? For example, if it's a dual core I will want 2 threads; quad core I will want 4 th...

threaded serial port IOException when writing

Hi, I'm trying to write a small application that simply reads data from a socket, extracts some information (two integers) from the data and sends the extracted information off on a serial port. The idea is that it should start and just keep going. In short, it works, but not for long. After a consistently short period I start to recei...

Why do I need to close fds when reading and writing to the pipe?

Here is an example to illustrate what I mean: #include <stdio.h> #include <unistd.h> #include <sys/types.h> int main(void) { int fd[2], nbytes; pid_t childpid; char string[] = "Hello, world!\n"; char readbuffer[80]; pipe(fd); if((childpid = fork()) == -1) { ...

How to process data in multiple threads using EJB3?

Sometimes it would be useful to distribute the processing of some data to several threads in an EJB3 session bean. Let's say that a stateless session bean fetches a lot of data from the database, splits it into several partitions and would like to spawn processing of those partitions in their own, parallel threads. What is the best way ...

Threading and Singletons

Before anyone flips out on me about singletons, I will say that in this instance it makes sense for me to have a singleton given the wide use of this object throughout my code and if someone has a better way short of DI I would like to hear but I would hope that this would not be the focus of this post, moreso helping solve it would be. ...

GUI thread detecting in the Qt libary

I need to know in the context of which thread my function is running, is it main GUI thread or some worker thread. I can't use a simple solution to store QThread pointer in the main function and compare it to QThread::currentThread() because I'm writing a library and I do not have access to the main function. I can of course create Init...

OpenMp C++ algorithms for min, max, median, average

I was searching Google for a page offering some simple OpenMp algorithms. Probably there is an example to calculate min, max, median, average from a huge data array but I am not capable to find it. At least I would normally try to divide the array into one chunk for each core and do some boundary calculation afterwards to get the result...

How do you handle a thread that has a hung call?

I have a thread that goes out and attempts to make a connection. In the thread, I make a call to a third party library. Sometimes, this call hangs, and never returns. On the UI thread, I want to be able to cancel the connection attempt by aborting the thread, which should abort the hung call to the third party library. I've called ...

Any reason NOT to slap the 'synchronized' keyword everywhere?

In my java project, almost every non-static method I've written is synchronized. I've decided to fix up some code today, by removing most of the synchronized keywords. Right there I created several threading issues that took quite a while to fix, with no increase in performance. In the end I reverted everything. I don't see anyone else ...

How Java Thread Class Determines Which thread?

While Going through the java tutorial on sun site, I see following piece of code: for (int i = 0; i < inputs.length; i++) { heavyCrunch(inputs[i]); if (Thread.interrupted()) { //We've been interrupted: no more crunching. return; } } Since Thread.interrupted() is a static function, how does java knows which ...

Is there a good podcast about concurrency?

Hi All, Concurrency is one of the hot topics on quite a few technology podcasts. Yet I couldn't find a podcast dedicated to concurrency programming fundamentals, techniques etc. If there's no podcast that specializes on concurrency which of technology podcasts highlights this topic best? ...