multithreading

Handling exceptions from Java ExecutorService tasks

I'm trying to use Java's ThreadPoolExecutor class to run a large number of heavy weight tasks with a fixed number of threads. Each of the tasks has many places during which it may fail due to exceptions. I've subclassed ThreadPoolExecutor and I've overridden the "afterExecute" method which is supposed to provide any uncaught exceptions ...

Why are certain lines in my Cocoa application taking forever to run?

I'm having a very strange problem. I'm running a loop in a detached thread, and some lines of code in my loop (different lines in each iteration of the loop) are taking a long long time (~45 seconds) to execute, even if they are simple commands like initializing an NSXMLDocument with data. This problem is also very inconsistent, and it d...

What are my options for doing multithreaded/concurrent programming in Python?

I'm writing a simple site spider and I've decided to take this opportunity to learn something new in concurrent programming in Python. Instead of using threads and a queue, I decided to try something else, but I don't know what would suit me. I have heard about Stackless, Celery, Twisted, Tornado, and other things. I don't want to have ...

Acquire a lock on two mutexes and avoid deadlock

The following code contains a potential deadlock, but seems to be necessary: to safely copy data to one container from another, both containers must be locked to prevent changes from occurring in another thread. void foo::copy(const foo & rhs) { pMutex->lock(); rhs.pMutex->lock(); // do copy } Foo has an STL container and ...

C# question on preventing GUI from becoming sluggish when using backgroundworker/thread

Hello all, I am trying to build a small application that logins into a server and gathers data from it constantly. The problem that I am having is that my GUI is slow to respond even when using either background worker or a thread. When my application tries to login into the server, I see "(Not Responding)" appear in my login form, but ...

Add a control on a form, from another Thread.

Hello to everyone. This is my first post on this site, which I must say is, great! Well here is my problem, and I truly hope someone will be able to help me. I was trying to postpone adding controls to my main form, with a goal to speed up it's start time. Well I run in the following exception: Cross-thread operation not valid: ...

Why does an instance of a generic class get altered on a separate thread when an instance of an ordinary class does not?

Hi, When an object is altered in a method that runs on a separate thread, the object is not altered on the calling thread (the thread that started the thread on which the method runs). However, if the class that defines the object is generic, the object gets altered on the calling thread. For example: I have two classes: public class...

Android thread in backgorund

Hi, i'm developing an Android application and i have a problem running a new thread in background. I make a class with this code: public class Downloader implements Runnable { private Vector <DownloadRequest>messages = new Vector<DownloadRequest>(); static final int MAXQUEUE = 5; ApiRequest mApi; public void run() { try { ...

Applet crashes when redirecting to a new url

Hi all, I'm developing an applet that makes some work and then a redirection to an URL when user clicks on a button. I'm using a SwingWorker to prevent GUI gets locked up. But when I run the applet I get this error after clicking the button: Exception in thread "SwingWorker-pool-1-thread-2" java.lang.IllegalMonitorStateException ...

.Net Thread.Suspend is obsolete. Looking for an alternative.

I did some research and looking around and it seems the way to do this is using an AutoResetEvent. I quickly put this together and it seems to work and seems to be thread-safe. Can I have some feedback? class Program { private Thread workerThread; private AutoResetEvent aResetEvent; private bool _continueProcessing; priv...

activating threads C#

i have this code in C#: Thread t1 = new Thread(functionsActivations(3, 4000, 0, 4)); Thread t2 = new Thread(functionsActivations(3, 4000, 5, 9)); t1.start(); t2.Start(); Thread t3 = new Thread(functionsActivations(4, 4000, 0, 4)); Thread t4 = new Thread(functionsActivations(4, 4000, 5, 9)); It is not working. How can I tell it to call...

C# Thread Termination and Thread.Abort()

Hi everyone! In MSDN description of the Thread.Abort() method stays: "Calling this method usually terminates the thread." Why not ALWAYS? In which cases it doesn't termenate the thread? Are there any other posibility to terminate threads? Regards, Lerax. ...

Queue<T>.Dequeue returns null

I have a scenario where multiple threads are pushing data on a Queue only ONE thread is processing data using code below code - while ( Continue ) { while ( queue.Count > 0 ) { MyObj o = queue.Dequeue(); someProcess(o); } myAutoResetEvent.WaitOne(); } But sometimes,...

does a getter function need a mutex?

I've a class that is accessed from multiple threads. Both getter and setter functions are guarded with locks. Are the locks for getter functions relly needed? Why? class foo { public: void setCount (int count) { boost::lock_guard<boost::mutex> lg(mutex_); count_ = count; } int count () { boost::lock_...

How can I represent state of method execution in base class without affecting the implementation in the derived classes?

I'm trying to create an abstract class, defining an abstract method, that is to be derived from other classes that implements some specific behavior in the abstract method. I want the abstract class to contain some kind of state information that represents however the implementation in the derived classes exited without errors, but I wan...

What might cause a Stack Overflow during linq iteration of Dictionary?

I have the following dictionary: Dictionary<long, ChangeLogProcess> _changeLogProcesses = new Dictionary<long, ChangeLogProcess>(); I have a method that attempts to get the next changelogprocess in the dictionary of a particular status (If there are no items of a particular status it returns null): var changeLogProcesses = ...

winsock 2. thread safety for simultaneous send's. tcp

is it possible to have multiple threads sending on the same socket? will there be interleaving of the streams or will the socket block on the first thread (assuming tcp)? the majority of opinions i've found seems to warn against doing this for obvious fears of interleaving, but i've also found a few comments that state the opposite. are ...

What is the recommended way for SWT Views (ViewPart) which receive a external event to update a GUI element?

My View is derived from ViewPart, but I have a listener on it which receives Events from non-GUI threads. If something is supposed to happen on within the GUI thread, it has to go through asyncExec(). So far so good. The thing is, the GUI elements are created in createPartControl(), so they can't be final. At the moment I just put th...

How to atomically increment a static member in IronPython?

I have an IronPython script that uses the TPL and Parallel.ForEach to process files using multiple threads. In C# I can use Interlocked.Add and Interlocked.Increment to change global variables in an atomic thread-safe operation, but this does not work in IronPython because integers are immutable. I currently have a simple Results class t...

How to force two Java threads to run on same processor/core?

I would like a solution that doesn't include critical sections or similar synchronization alternatives. I'm looking for something similar the equivalent of Fiber (user level threads) from Windows. ...