multithreading

Dead Lock Thread Check

Hi Experts, Can somebody tell me how can I find out "how many threads are in deadlock condition" in Java multi-threading application? What is the way to find out the list of deaklock threads? I heard about Thread Dump and Stack Traces but I don't know how to implement it. I also want to know what all new features have been introduced...

How to return a function value with decorator and thread

have this code import threading def Thread(f): def decorator(*args,**kargs): print(args) thread = threading.Thread(target=f, args=args) thread.start() thread.join() decorator.__name__ = f.__name__ return decorator @Thread def add_item(a, b): return a+b print(add_item(2,2)) but ...

VB9 New thread with multiple parameters

I'm trying to create a new thread and send multiple parameters as well as a delegate to report back. In VB8 I always hate to do this because it requires either introducing a new class/structure or a delegate. Is there any better way to do this in VB9 ? I'm looking for a solution something like this : Dim Th As New Thread(AddressO...

Why is swallowing InterruptedException ok for subclasses of Thread ?

In Brian Goetz's article on how to handle InterruptedException, one paragraph stands out: The one time it's acceptable to swallow an interrupt is when you know the thread is about to exit. This scenario only occurs when the class calling the interruptible method is part of a Thread, not a Runnable. I don't get this. Is the reason ...

How to use wait and notify in java?

Hello, I have 2 matrices and I need to multiply them and then print the results of each cell. As soon as one cell is ready I need to print it, but for example I need to print the [0][0] cell before cell [2][0] even if the result of [2][0] is ready first. So I need to print it by order. So my idea is to make the printer thread wait until...

Synchronising multiple threads in python

I have a problem where I need x threads to wait until they have all reached a synchronization point. My solution uses the synchronise method below which is called by each threaded function when they need to synchronise. Is there a better way to do this? thread_count = 0 semaphore = threading.Semaphore() event = threading.Event() def s...

How to handle exceptions raised in other threads when unit testing?

When testing with Visual Studio Team Test unhandled exceptions in tests are caught and reported in the results. So I was kind of surprised to see the test hosting process (VSTestHost.exe) crash and showing the system crash dialog. Upon further investigation this crash was an unhandled exception raised in another thread (more directly, i...

How do I terminate a thread waiting on @synchronized objective C

Hey there, I have some code like this: doDatabaseFetch { ... @synchronized(self) { ... } } and many objects that call doDatabaseFetch as the user uses the view. My problem is, I have an operation (navigate to the next view) that also requires a database fetch. My problem is that it hits the same synchronize block and ...

Thread-safe async byte queue

I've got a callback method that is called whenever new data is available: public delegate void DataCallback( byte[] buffer, int offset, int count); I want to wrap this in a class that implements an interface similar to this: public interface IDataSource { IAsyncResult BeginRead( byte[] buffer, int offs...

Capture .Net Thread End Event

I would like an elegant way to capture a thread end/exit event. I've found two approaches so far: Use background worker, which has a RunWorkerCompleted event, or, Have my thread worker explicitly call an "I'm Exiting" delegate. Yes, these will work, but there must be some way from the parent thread (the thread that calls the Thread.S...

Sample code to illustrate a deadlock by using lock(this)

I've read several articles and posts that say that lock(this), lock(typeof(MyType)), lock("a string") are all bad practice because another thread could lock on the same key and cause a deadlock. In order to understand this problem, I was trying to create some sample code to illustrate the deadlock but have been unable to wrap my head ar...

Win32 function for scheduled tasks in C++

I have a function in C++ that needs to be called after a period of time and this task is repeated. Do you know any built-in function or sample code in Win32 or pthread? Thanks, Julian ...

What is the best approach to schedule Callables which may time out in a polling situation?

I have several Callables which query for some JMX Beans, so each one may time out. I want to poll for values lets say every second. The most naive approach would be to start each in a separate thread, but I want to minimize the number of threads. Which options do I have to do it in a better way? ...

wxpython & threads: How to simulate a trigger of an wx.EVT_BUTTON?

Hi, If I have a 'parent' window (wxFrame), and a plugin window. (parent.py) class App(wx.App): wxctrl = xrc.XRCCTRL( self.x_panel, "BUTTON") wx.EVT_BUTTON(wxctrl, wxctrl.GetId(), self.OnButton) How could I send an event from plugin.py that mimics clicking 'Button'? ...

C++ Threading Question

I have an object Foo which has a global variable, Time currentTime Foo has two methods which are called from different threads. update() { currentTime = currentTime + timeDelay; } restart(Time newTime) { currentTime = newTime; } I am seeing behavior on a restart, the time changes correctly and other times where currentTime d...

How to wait on WaitHandle without message pumping?

I want to call WaitHandle.WaitOne(TimeSpan) in .NET, but I'm on the STA thread and it pumps messages while waiting. For reasons that are beyond the scope of this question, I need to wait without pumping. How can I wait for a WaitHandle to be signaled without pumping messages? It seems in some scenarios that WaitHandle.WaitOne does not...

How to ensure that only table row will be created with a particular state ?

I have a domain object that looks something like this: class UserStuff { String userid; boolean primordial; } In the table, primordial is a TINYINT. A User can have possibly many UserStuff. What I want to ensure is that only one row (the first row created) will have primordial == 1. All subsequent rows will have primordial ==...

Java : Is ServerSocket.accept threadsafe ?

For a project in school, we are making a multithreaded server in Java 5.0. This project is centered on the concurrence aspect of a server. We have some threads dedicated to treating the requests. To do so, they have a call to a ServerSocket.accept() to accept new connections. Our choice was to start a bunch of them and let them treat th...

"AsyncFuture<T>" or what? Future<T> obtained in a background thread -- is it a pattern?

I'd like to have some work done in a background thread as simple as creating a Future var for it and then asking later for the calculated value. In pseudo-C#-code: AsyncFuture<int> asyncFuture = new AsyncFuture<int>(FuncToCalculateValue); //do some other work, or draw UI if(asyncFuture.NoErrorsHappened){ int realResult = asyncResu...

PBS (torque) fails to consider quad core processors as 4 processors

I have a Debian cluster with 2 nodes and two quad-core processors each. I use Torque and Maui as scheduler. When I try to run an MPI job with 16 processes, the scheduler is not able to run the job: either it puts it to the queue (although there is not any job runing at that moment) or runs and the resulting output file says that you was ...