multithreading

How do I handle exceptions when using threading and Queue?

If I have a program that uses threading and Queue, how do I get exceptions to stop execution? Here is an example program, which is not possible to stop with ctrl-c (basically ripped from the python docs). from threading import Thread from Queue import Queue from time import sleep def do_work(item): sleep(0.5) print "working" , ...

What is the reasoning behind the double call to WeakHashMap.put( .. ) ?

This blog post demonstrates a way to implement a mutex per string id idiom. The String ids used are to represent HttpSession ids. Why do we need to wrap a WeakReference around the Mutex instances ? Isn't it better to just create a Map from String -> Mutex ? Why do we need to call put twice ? public Mutex getMutex( String id ) { ...

Incompatible signatures when spawning thread with ThreadPool.QueueUserWorkitem

The error is: Method 'Private Sub ProcessToolWork()' does not have a signature compatible with delegate 'Delegate Sub WaitCallback(state As Object)'. What's the deal here? I've never experienced this error spawning a thread in this fashion. Here are my routine definitions: Public Sub ProcessWork() ThreadPool.QueueUser...

Java thread wait and notify

I have two threads. Thread A is pulling some elements from queue and thread B is adding some elements to the queue. I want thread A to go to sleep when the queue is empty. When thread B adds some element to the queue it should make sure that thread A is working. How can this be done in Java? ...

WritableBitmap does not work on separate Thread?

I've got a WritableBitmap that updates on a separate thread, specifically in response to an event. myWritableBitmap.Lock(); CopyMemory(myWritableBitmap.BackBuffer, ...); myWritableBitmap.AddDirtyRect(...); myWritableBitmap.Unlock(); When run on a separate thread as-is, the Lock() command throws a System.InvalidOperationException. If I...

If you call EventWaitHandle.Set() X times, will it signal X threads if X the threads haven't started yet?

In other words I have a thread that starts and calls waitHandle.Set() multiple times. Then I start several threads and each is waiting on that WaitHandle. Will X of the them be signaled where X is the number of times the original thread called waitHandle.Set()? Is there a structure that supports what I'm trying to accomplish more closel...

Is there a way to wait on multiple semaphors

I'm trying to write an application that can wait on multiple resource pools at once. Each resource pool is controlled by a Semaphor. Can I use WaitHandle.WaitAll() where I pass in the entire list of semaphors? Is there a potential deadlock issue with this implementation? My current implementation: namespace XXX { using System.Colle...

c#.net looping thread stack overflow

I am trying to run a task in the background checking a database for a number of records in a table, and if the number has changed since the last check, get those records, and do some work on them. Using the following code, I'm getting a stack overflow after about two hours. The application is doing nothing during this time, just chec...

Non threadlocked Mutex

This is an offshoot of this question but with a few constraints removed. I have a system where I need to manage file locking. I need to be able to lock a file (shared read locking) in one thread and then unlock it in another. More accurately, I can't be sure what thread it will be unlocked in or even if the creating thread is still arou...

Strange Behavior When Changing Exclusively Locked Object - Monitor.Enter(x)

I wanted to see what happened if you change the reference of an object exclusively locked by Monitor.Enter(). As expected a SynchronizationLockException was thrown. But I was surprised to see several threads getting past the Monitor before the exception was thrown. Here's what the code below is doing. create and start 100 threads mak...

Deferring BufferedWriter.write to another thread

I have an event processing scheme which should also eventually write to file; I cannot afford to delay the event when the file is being flushed, i.e. waiting to the end of BufferedWriter.write(String). I'm looking for the easiest way to achieve that (is there's a library doing that? I reckon that I'm not the only one who had this proble...

Using Python multiprocessing while importing a module via file path

I'm writing a program which imports a module using a file path, with the function imp.load_source(module_name,module_path). It seems to cause a problem when I try to pass objects from this module into a Process. An example: import multiprocessing import imp class MyProcess(multiprocessing.Process): def __init__(self,thing): ...

C# joining threads in background worker DoWork()

Hello, In my DoWork() function I register with our sip server. Then I have to wait for a response back. However, the response I get is received in another event. However, before I am able to check the flag in the DoWork() the DoWork() has all ready finished and the response comes after. I am trying to find a way to wait in the DoWork(...

NSOperation on the iPhone

I've been looking for some concrete scenarios for when NSOperation on the iPhone is an ideal tool to use in an application. To my understanding, this is a wrapper around writing your own threaded code. I haven't seen any Apple demo apps using it, and I'm wondering if I'm missing out on a great tool instead of using NSThread. The ideal s...

Automatically detect hanging threads

I'm currently looking for a way to identify hanging threads in java. Anyone knows whats the best way to do this? Currently I could think off 2 possible ways to do this: Calling a (callback-)method periodically within all methods of the Application. This seems a "bit" complex and unsightly... Moreover I have no control when calling ext...

Determining the source of a thread

I've been experiencing a high degree of flicker and UI lag in a small application I've developed to test a component that I've written for one of our applications. Because the flicker and lag was taking place during idle time (when there should--seriously--be nothing going on), I decided to do some investigating. I noticed a few threads ...

thread with multiple parameters

Does anyone know how to pass multiple parameters into a Thread.Start routine? I thought of extending the class, but the C# Thread class is sealed. Here is what I think the code would look like: ... Thread standardTCPServerThread = new Thread(startSocketServerAsThread); standardServerThread.Start( orchestrator, initializeMembe...

Best Practices for asynchronous calls in MVP with WinForms

I am using the Model-View-Presenter pattern in a WinForms project and one problem (among many) that I am having is when the form tells the presenter to do something and then is un-reactive while the presenter goes of to do it. Fortunately in my project I have no problem with making all presenter calls asynchronous the question is how ex...

I need a message pump that doesn't mess up my open window

My application (the bootstrap application for an installer that I'm working on needs to launch some other applications (my installer and third party installers for my installer's prerequisites) and wait for them to complete. In order to allow the GUI to do screen updates while waiting for an app to complete, I put a message pump in the w...

WCF Concurrent requests piling up on the server when using WSHttpBinding

I have a WCF client/server app which is communicating over HTTP using the WSHttpBinding. Server Setup: self-hosting, using the standard WCF ServiceHost. My actual service class is attributed as: [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerSession, UseSynchronizationConte...