multithreading

PyQT4 and Ctrl C

I have a programs that runs several threads (on a while loop until Ctrl C is pressed). The app also has a GUI that I developed in PyQt. However, I am facing the following problem: If I press Ctrl C on the console, and then close the GUI, the program exits fine. However, if I close the GUI first, the other threads won't stop and the prog...

How does a synchronized statement work in this case?

Assume I have a class like this: public class Server { public static void main(String[] args) { Map<Integer, ServerThread> registry = Collections.synchronizedMap(new LinkedHashMap<Integer, ServerThread>()); ... while(true) { Socket socket = serverSocket.accept(); ServerThread serverThread = new...

Question about Thread + iPhone

I am having a confusion with threads. Suppose I start a thread in a ViewController which is doing some heavy processing. If I pop the viewController while the thread is still in execution will the thread stop executing or whether it will continue its execution. ...

Threading in Rails - do params[] persist?

Hi, I am trying to spawn a thread in rails. I am usually not comfortable of using threads as I will need to have a in-depth knowledge of Rails' request/response cycle, yet I cannot avoid using one as my request times out. In order to avoid the time out, I am using a thread within a request. My question here is simple. The thread that I...

Displaying JWindow in the event dispatching thread

What I am trying to do is have a small splash screen appear while my program is loading something. This is what I have: SplashScreen.showSplashScreen(); // Do stuff that takes time. SplashScreen.hideSplashScreen(); All the showSplashScreen() method does is create a new JWindow in the middle of the screen and make it visible. Now this...

how do i send a custom message to a windows service?

I have implemented a windows xp service application that starts a couple of working threads. From one of the threads i need to send custom messages back to the service. How do i do that? ...

How to prevent an OpenGL application from drawing?

Hello everybody! How can i prevent an external OpenGL application(no sources available) from drawing like it can be done by GDebugger? The problem is Dassault Catia that opens complex models within five(!) hours because they are rendered while the loading is in process. When the border of this application is clicked and the mouse bu...

Multi-thread/parallel requests in PHP

How can I make multi-thread (parallel) GET requests in PHP? I know that there is a CURL multi-thread support, but there is no limit of active requests number and actual callbacks configuration for every success request completion. ...

Java WS Authenticator Problem

Hi all, at the moment I am struggling with a bug in Sun's class 'java.net.Authenticator'. It seems that the Authenticator class has a system wide static Authenticator. This results in the following problem in my multi-threaded application. Thread 1 - Authenticates for User 1 Thread 2 - Authenticates for User 2 Thread 1 - Executes the c...

Thread-safe lazy get and release

Hello All, I'm running into kindof an annoying problem and would need some advice... Let's say I have a bunch of small MyObject's, that can construct bigger MyExtendedObject's. MyExtendedObject's are big and CPU consuming so construction is lazy, and I try do remove them from memory as soon as possible: MyExtendedObject * MyObject::Ge...

Difference between "free-threaded" and "thread-safe"

Sometimes I see the term "free-threaded" to describe a class or a method. It seems to have a similar or identical meaning to "thread-safe". Is there a difference between the two terms? ...

How to adapt my current splash screen to allow other pieces of my code to run in the background?

Currently I have a splash screen in place. However, it does not work as a real splash screen - as it halts the execution of the rest of the code (instead of allowing them to run in the background). This is the current (reduced) arquitecture of my program, with the important bits displayed in full. How can I adapt the splash screen curr...

Why SynchronizationContext does not work properly?

I have following code: [TestMethod] public void StartWorkInFirstThread() { if (SynchronizationContext.Current == null) SynchronizationContext.SetSynchronizationContext( new SynchronizationContext()); var syncContext = SynchronizationContext.Current; Console.WriteLine("Start work in the first thread ({0}...

Restarting normal Threads

Let's say that what I want to do is to validate one million strings, and each validation takes a couple of seconds. My approach: I have an array of threads declared like this: Thread[] workers = new Thread[50]; I don't have all strings in an array, they are got through some calculations, then I don't have all of them when I start th...

WPF: Problems with CurrentDispatcher.CheckAccess and CanExecuteChanged

Sometimes when I call RaiseEvent CanExecuteChanged(sender, EventArgs.Empty) from a back ground thread it give me an exception stating "The calling thread cannot access this object because a different thread owns it." However, if I call System.Windows.Threading.Dispatcher.CurrentDispatcher.CheckAccess is returns True. What am I doing w...

What does java "VM thread" do?

I use jstack to output the thread info. And there is a thread: "VM Thread" prio=10 tid=0x0878b400 nid=0x760a runnable What is this thread used to do? It takes 50% CPU usage and most of CPU time ...

'deadlock detected' error in rails

Hi, I have deadlock detected error in my code and don't understand why. Could someone please tell me what am I doing wrong? #!/usr/bin/ruby ENV['RAILS_ENV'] = ARGV.first || ENV['RAILS_ENV'] || 'development' require File.expand_path(File.dirname(__FILE__) + "/config/environment") mutex = Mutex.new threads = [] 1.upto(10) do |i| t...

Python threads and global vars

Say I have the following function in a module called "firstModule.py": def calculate(): # addCount value here should be used from the mainModule a=random.randint(0,5) + addCount Now I have a different module called "secondModule.py": def calculate(): # addCount value here too should be used from the mainModule a=random.rand...

Synchronizing producer, consumer and a producer queue.

Hello! I have a producer and a consumer. Producer fills its internal queue with objects, consumer takes these objects one by one. I want to synchronize the cosumer with the producer, so that the consumer blocks when there are no objects ready, and I want to synchronize the producer with itself, so that it stops producing when the queue i...

Testing a semaphore by counting.

There’s an article about semaphores on OS X. The author tests the semaphore by incrementing and decrementing a static variable in two threads. With semaphore guarding the variable access, the variable ends up being zero. Without the guard the variable ends up having some bogus value. I tried the code and it works. What I don’t understand...