multithreading

Session management using Hibernate in a *multi-threaded* Swing application

Hi, I'm currently working on a (rather large) pet project of mine , a Swing application that by it's very nature needs to be multi-threaded. Almost all user interactions might fetch data from some remote servers over the internet , since I neither control these servers nor the internet itself, long response times are thus inevitable. A ...

Process n items at a time (using threads)

I'm doing what a lot of people probably need to do, processing tasks that have a variable execution time. I have the following proof of concept code: threads = [] (1...10000).each do |n| threads << Thread.new do run_for = rand(10) puts "Starting thread #{n}(#{run_for})" time=Time.new while 1 do if Time.new - tim...

Request thread to quit without forcing it?

I am writing an app. There are plugins which DL resource from the net. If the user would like to quit i would not like any DLs to start but i would like DLs in progress to continue until done. After they stop i would gracefully quit. How do i find out if a thread is in a middle of a DL or just sleeping? The actual download resource func...

Do threads share the heap?

As far as I know each thread gets a distinct stack when the thread is created by the OS. I wonder if each thread has a heap distinct to itself also? ...

Volatile variable

Where is a volatile variable stored in the stored in program memory(in which section) ? ...

How port WaitForMultipleObjects to Java?

Hello fellows! I have some code in C++ for Windows and I intend to port it to Java. But unfortunately it is not so easy as I thought. Could someone help me, please? Please, take a look at algorithm: HANDLE hExitEvent; HANDLE hDataAvailabeEvent; while(true) { WaitForMultipleObjects(); if (hExitEvent is set) break; if (hDataA...

A multithreaded queue in Python

I need to perform time consuming tasks in an webapplication. Because the tasks can be so heavy that they run for minutes they have to run on multiple threads so the user won't have to look at a loading page for minutes. So I thought a multithreaded queue would be a good solution. Each instance of a object that you add to the queue shoul...

Multiple threads and memory

I read in the Visual C++ documentation that it is safe for multiple threads to read from the same object. My question is: how does a X86-64 CPU with multiple cores handle this? Say you have a 1 MB block of memory. Are different threads literally able to read the exact same data at the same time or do cores read one word at a time with ...

Any issues with large numbers of critical sections?

I have a large array of structures, like this: typedef struct { int a; int b; int c; etc... } data_type; data_type data[100000]; I have a bunch of separate threads, each of which will want to make alterations to elements within data[]. I need to make sure that no to threads attempt to access the same data element at t...

Are mutexes really slower ?

I have read so many times, here and everywhere on the net, that mutexes are slower than critical section/semaphores/insert-your-preferred-synchronisation-method-here. but i have never seen any paper or study or whatever to back up this claim. so, where does this idea come from ? is it a myth or a reality ? are mutexes really slower ? ...

Is it possible to list all the threads currently running in .NET

I'd like to list as much information about all the threads currently running in .NET1.0 as I can. I don't have the luxury of adding threads to an internal list of my own when they get created; I just want to dump out a list of those that are currently in the system. Does any one know a way of doing this? I've been looking at the System.T...

UIImage within Thread not being Released / Overwritten

This appears to be the the classic method for scanning images from the iPhone. I have a thread that is dispatched from the main thread to go and scan for Codes. It essentially creates a new UIImage each time then removes it. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; { while (![thread isCancelled]) { #ifdef DE...

How can I tell reliably if a boost thread has exited its run method?

I assumed joinable would indicate this, however, it does not seem to be the case. In a worker class, I was trying to indicate that it was still processing through a predicate: bool isRunning(){return thread_->joinable();} Wouldn't a thread that has exited not be joinable? What am I missing... what is the meaning of boost thread::joi...

What happens when a .NET thread throws an exception?

We have an interface IPoller for which we have various implementations. We have a process that will take an IPoller and start it in a separate thread. I'm trying to come up with a generic way of providing exception handling for any IPollers which don't do it themselves. My original thinking was to create an implementation of IPoller t...

C# multi-threading: Acquire read lock necessary?

Is it necessary to acquire a lock on a variable before reading it from multiple threads? ...

How to create a MFC dialog with a progress bar in a separate thread?

My application may take a while to connect to a database. This connection is made with a single library function call, i.e. I cannot put progress updates in there and make callbacks or something similar. My idea was to create a dialog with a progress bar in a separate thread before connecting to the DB. This dialog will continually ch...

How to unit test that ExecutorService spawns new thread for task?

How does one unit test that a new thread was spawned for a Runnable task when using an ExecutorService? Basically, I have a static thread pool for my application. public static final ExecutorService executorService = Executors.newCachedThreadPool(); I'd like to use this thread pool for the my unit tests, rather than mocking one out o...

Eating up processing power

In C#, is there a way to make a program that simply "eats" roughly 20% of my processing power? In other words, I want my CPU to run at 80% power. ...

python chat client lib

Hi, I'm trying to write a python lib that will implement the client side of a certain chat protocol. After i connect to the server i start the main loop where i read from the server and handle received commands and here i need to call a callback function (like on_message, or on file_received, etc). How should i go about implementing this...

Using a thread to capture process output

I am using a thread to capture stream output from a process, and then outputting that stream to the eclipse console. The question I have is when to terminate the thread that is doing the stream output. Thread t = new Thread(new Runnable(){ private boolean isProcessDone(Process p) { //not sure what to do here } public void run...