multithreading

How to interrupt the Thread when it is inside some loop doing long task?

Possible Duplicate: How do you kill a thread in Java? I need to stop doing some big task by sending the interruption signal to the Thread. I am using most of the APIs from java.util.concurrent.*. My task is send to the Thread and is executed. This task comes from the client so I do not have any control over that code. Task are someth...

How to creat a class level mutex , which work across process

I have a class which logs to a file .this class is used by multiple threads. I have use a mutex inside the write function and it works fine with one instance of my application . but if I start multiple instance of the application the it crashs. what is the correct implementation of named mutex at class level that can work across proce...

Scheduling issues in python

I'm using python to interface a hardware usb sniffer device with the python API provided by the vendor and I'm trying to read (usb packets) from the device in a separate thread in an infinite loop (which works fine). The problem is that my main loop does not seem to ever get scheduled again (my read loop gets all the attention). The cod...

ManualResetEvent WaitOne not unblocking

I'm a little confused over a ManualResetEvent that I'm using which doesn't appear to be unblocking. Anyone know why this might be the case? The scenario I've got is something along these lines. The real situation is quite complicated and I've not managed to isolate a section of code that's reasonable to post to reproduce the issue. EDI...

Threadsafe way to add and remove items from list in .Net

I want to add items to a list from one thread and from another thread remove items from the same list. However, I am not sure if I will run into problems with multiple threads accessing the same object. I have read a bit on the lock statement but I am not sure how to implement this. In short, the question is, how do I ensure thread safe...

How can I alter XAML elements from a backgroundworker thread?

In the following code example, I want to change the color of the Foreground text of a TextBox from my BackgroundThread, but it gets the error: This thread cannot access this object since it is in another thread. What do I have to change in the code below so that the background worker thread can change the foreground color in the ...

Enumerating threads in Windows

How can I enumerate all of the threads in a process given a HANDLE to the process (or a process ID)? I'm interested in doing this so I can further do an EnumThreadWindows on each thread. ...

How to workaround lack of multiple ao.lock?

I'm programming a simple pyS60 app, not really done anything with python or using multiple threads before so this is all a bit new to me. In order to keep the app open, I set an e32.Ao_lock to wait() after the body of the application is initialised, and then signal the lock on the exit_key_handler. One of the tasks the program may do is...

WPF Dispatcher.BeginInvoke and UI/Background Threads

I think I need some clarifications regarding WPFs Dispatcher.Invoke and Dispatcher.BeginInvoke usage. Suppose I have some long running 'work' code like such that is invoked on the press of a button in a simple WPF application: longWorkTextBox.Text = "Ready For Work!"; Action workAction = delegate { Console.WriteLine("Starting W...

Options for informing a Thread to stop

I need to inform a so-called worker thread to stop work at the next available oppertunity. Currently I'm using something like this: public void Run() { while (!StopRequested) DoWork(); } The concern I have is that StopRequested is being set to True on a different thread. Is this safe? I know I can't l...

How to wait on events on a second thread

Consider the following code in a class called Worker FileSystemWatcher watcher = new FileSystemWatcher(); public void Run() { watcher.Path = @"c:\queue"; watcher.Created += new FileSystemEventHandler(watcher_Created); watcher.EnableRaisingEvents = true; } Now here's what I would like to do wih t...

Can I access the TLS of a DIFFERENT thread?

Long story short, I'm working on a .NET profiler that at one point gets a notification that a managed thread is running on a certain native kernel thread, which is not the currently executing thread. In this notification, I'm hoping to record a pointer in the TLS of the target thread. Again, that's not the current thread. I'm not seeing...

Python: Why does `sys.exit(msg)` called from a thread not print `msg` to stderr?

Hello! Today I ran against the fact, that sys.exit() called from a child-thread does not kill the main process. I did not know this before, and this is okay, but I needed long time to realize this. It would have saved much much time, if sys.exit(msg) would have printed msg to stderr. But it did not. It turned out that it wasn't a real ...

Java Wait-For-Thread Question

I have a thread and I need to wait for its result, like this: t1.start(); while (variableModifiedByMyThread == null) { /* do nothing */ } // "t1" set the value of "variableModifiedByMyThread" The code above is working, but not a very nice solution... Is this code doing the same thing (is it waiting for the "t1" thread)? t1.start...

Return a value from a Event -- is there a Good Practice for this?

I am doing a small multithreaded app that uses asynchronous TCP sockets, but I will get to the point: I am using a custom event to read a value from a form and the delegate used by the event returns a string when finished. My question here is: is that correct? is it Ok to return values from the events? or is there a best way to do this?...

Implementing Monitor with signaling using mutex and condition variable in C++

Did any body implemented a Monitor with signaling (wake up waiting threads) using a mutex and condition variables in C++. I dont know how to start. Any sample code or online article will be great. Are there any open source libraries who have implemented these? I need for windows and linux. But to start with windows(win32) will be fine....

Multithreaded compression in C#

Is there a library in .net that does multithreaded compression of a stream? I'm thinking of something like the built in System.IO.GZipStream, but using multiple threads to perform the work (and thereby utilizing all the cpu cores). I know that, for example 7-zip compresses using multiple threads, but the C# SDK that they've released doe...

Multithreading - Synchronization on Unix

Hi, I am facing sync related issue in multi threading. I have an shared library which applications use to build there applications. From the library I have created a thread which listen to the request coming and process it its is real time thread.From the library i have invoked an API which is sync in nature which will wait for response ...

Threads or JMS Which is better?

If i want to run a process (time taken to complete this process is in hours) in multi-user environment (thru tomcat-servlet) Which is better to implement this process in? 1) In Threads or 2) In JMS what are advantages and disadvantages? ...

Windows Service terminated unexpectedly

Hi, I have a windows service which has a number of threads that do some work. All has been going well in testing, until once, where I saw "windows service terminated unexpectedly" in the event viewer. How do I go about trying to debug where this is happening? I have exceptions being caught under normal circumstances but not in this c...