multithreading

Why do my Perl threads execute randomly on the first run but in order on subsequent runs?

In the course of testing the code for the question How can I store per-thread state between calls in Perl? I noticed that the first I time execute the script the threads execution are fairly well interleaved with each other. But on all subsequent executions of the script all the threads run almost perfectly in the order of their creatio...

What is the best way to do multithreading or asynchronous task in .NET with return value?

What would be the best way to do multithreading or asynchronous task in the following situation in C#? The simplified situation: A http request needs to make 5 or more web service calls. Upon completion each web service call will receive and return a string list as a result. The caller (of 5 web service calls) need to merg...

How should I terminate a looped sub-thread in Java?

Hi, I'm new to Java I need to do some clean up work when I am going to terminate a looped thread. Such as saving a buffer so I can continue later. PseudoCode: private class CalculatePI(Byte[] resume) implements Runnable{ public void Run(){ while(true){ resume=resumeCalculating(resume); } } } Thread cal...

Question on a tutorial

Hello, i´m trying to get following tutorial to run and understand: http://www.ibm.com/developerworks/web/library/wa-cometjava/index.html In the example code which can be downloaded at the bottom of the page is everything in one class with two inner classes. How can i make the the thread of "MessageSender" (Listing 3) visible to "The ...

How to assign separate thread for each File System Watcher?

I am developing a database file system.It includes a multi-directory watcher which is a windows service and which uses the file system watcher class from .net. I want to run each watcher class on separate thread.Thread can not be extended in .net because as it is "Sealed". What I want is, run all the methods of my watcher class in the r...

graceful thread termination with pthread_cond_signal proving problematic.

Hi I need to fire of a bunch of threads and would like to bring them down gracefully. I'm trying to use pthread_cond_signal/pthread_cond_wait to achieve this but am running into a problem. Here's my code. firstly the thread_main static void *thrmain( void * arg ) { // acquire references to the cond var, mutex, finished flag and ...

Ruby, MongoDB: How to share a Cursor between threads?

The following does not work. The call to resources.next_document within the thread returns nil. The same call without threading works as expected. Any MongoDB experts out there? :P resources = db[Resource::COLLECTION].find number_of_threads.times do threads << Thread.new do while resource = resources.next_document ...

WPF UI Thread Status

I have a wpf application that takes ~30 seconds to create a map/graphic. I have read there is no easy way to tie into the UI rendering thread to get a progress update. So I was going to use a counter on a value converter which colors my map but that is also on the UI Thread, so my question is has anyone found any slick methods of worki...

Looping threads accessing pthread mutex

Hey all im building this application in which i have a client represented by a thread, running in loop (until it receives the instruction to terminate) trying to access a critical section of data in the server. When the first client connects to the server, he owns the lock to that mutex. all the subsequent connections are put to a hold...

Is Perl's inet_aton thread-safe?

Is inet_aton Thread-Safe? I know according to UNP that POSIX doesn't require a lot of the Sockets API to be thread safe, and so I have to assume they're not, but in general how do I know if something is thread safe in Perl? To what extent do I need to lock library function that I call? And how do I lock them? When I try something lik...

How to dispatch work items to a single thread

Sorry this question is not very clear, if I know the correct words to describe the problem, Google would be likely to come up with the answer. I am looking for a queue class that: Lets any number of threads put an item on the queue Items are processed in the order they are added to the queue I don’t mind what thread process an item On...

What is process and thread?

Yes, I have read many materials related to operating system. And I am still reading. But it seems all of them are describing the process and thread in a "abstract" way, which makes a lot of high level elabration on their behavior and logic orgnization. I am wondering what are they physically? In my opinion, they are just some in-memory "...

What are the reasons why the CPU usage doesn’t go 100% with C# and APM?

I have an application which is CPU intensive. When the data is processed on a single thread, the CPU usage goes to 100% for many minutes. So the performance of the application appears to be bound by the CPU. I have multithreaded the logic of the application, which result in an increase of the overall performance. However, the CPU usage h...

How to run parallel codes using QT ?

I am developing a simulator. I have chosen QT for the GUI. My project involves a lot of manipulation of data and I use QT just to plot my results. My code structure is such that my main function contains a global object of my data, an object of the QT GUI and other objects for manipulating this data. I need to modify this data at every...

What should I know about multithreading and when to use it, mainly in c++

I have never come across multithreading but I hear about it everywhere. What should I know about it and when should I use it? I code mainly in c++. ...

Is it possible to group/isolate tasks in ThreadPool when using WaitHandle.WaitAll?

The scenario I am facing is as below. Because ThreadPool is 1 instance per process so my question is that would method 1 cancel tasks queued by method 2 after 3 seconds? http request comes in *method 1 gets executed first*: ThreadPool.QueueUserWorkItem x 3 WaitHandle.WaitAll for 3 seconds *method 2 gets executed after method 1...

Explanation of Text on Threading in "C# 3.0 in a Nutshell"

While reading C# 3.0 in a Nutshell by Joseph and Ben Albahari, I came across the following paragraph (page 673, first paragraph in section titled "Signaling with Wait and Pulse") "The Monitor class provides another signalling construct via two static methods, Wait and Pulse. The principle is that you write the signalling logic yourse...

Mutex needed in MSMQ?

I'm browsing source codes from two applications sharing one queue using MSMQ. The first application has a thread that writes into the queue while the second application has another thread that reads from the queue. Ordinarily, if you're implementing your own queue, the applications would need a mutex when accessing the queue, right? Howe...

Non-recursive mutex ownership

I read this somewhere in SO: "recursive mutex has a sense of ownership, the thread that grabs the mutex must be the same thread that releases the mutex. For non-recursive mutexes, there is no sense of ownership and any thread can release the mutex no matter which thread originally locked the mutex." I'm confused by the last statement. C...

java thread reuse

I have always read that creating threads is expensive. I also know that you cannot rerun a thread. I see in the doc of Executors class: Creates a thread pool that creates new threads as needed, but will reuse previously constructed threads when they are available. Mind the word 'reuse'. How do thread pools 'reuse' threads? ...