multithreading

Design question regarding threads

Hi I have class A and classes B and C. class B runs one thread and class C runs n threads. class A should start the threads and than wait for a signal from the user (say Ctrl-c in Linux) - class A will stop all threads (of classes B and C), do some final work and the application will exit. The question is: how should class A sleep unti...

Python Socket Getting Connection Reset

I created a threaded socket listener that stores newly accepted connections in a queue. The socket threads then read from the queue and respond. For some reason, when doing benchmarking with 'ab' (apache benchmark) using a concurrency of 2 or more, I always get a connection reset before it's able to complete the benchmark (this is taking...

How to get an item from a set of Queues?

Hello. Say there are two empty Queues. Is there a way to get an item from the queue that gets it first? So I have a queue of high anonymous proxies, queues of anonymous and transparent ones. Some threads may need only high anon. proxies, while others may accept both high anon. and just anon. proxies. That's why I can't put them all to a...

Lock dictionary within same thread

I have a function that returns an entry on a dictionary, based on the Key (name) and if it doesn't exist, returns a newly created one. The question I have is with the "double lock" : SomeFunction locks the _dictionary, to check for the existance of the key, then calls a function that also locks the same dictionary, it seems to work bu...

Are final static variables thread safe in Java?

I've read around quite a bit but haven't found a definitive answer. I have a class that looks like this: public class Foo() { private static final HashMap<String, HashMap> sharedData; private final HashMap myRefOfInnerHashMap; static { // time-consuming initialization of sharedData f...

Java concurrency - Should block or yield?

Hi, I have multiple threads each one with its own private concurrent queue and all they do is run an infinite loop retrieving messages from it. It could happen that one of the queues doesn't receive messages for a period of time (maybe a couple seconds), and also they could come in big bursts and fast processing is necessary. I would l...

What "thread safe" really means...In Practical terms

Dear all, please bear with my newbie questions.. I was trying to convert PDF to PNG using ghostscript, with ASP.NET and C#. However, I also read that ghostscript is not thread safe. So my questions are: 1) What exactly does "ghostscript is not thread safe" mean in practical terms? What impact does it have if I use it in a live ASP.NET(...

boost threadpool - documentation and examples

I'm looking for documentation on boost::threadpool. I downloaded the source and documentation zip files. The documentation directory is just about empty. It says to look at src/examples/mergesort.cpp. It ain't there. In fact, there is no src/examples directory. Anyone know if there is a Roseta Stone, and if so where? ...

Add content asynchronously (threading + ajax).

Ok what id like to do is to load a page that displays 90% of content, and load the last 10% asynchronously. As im rendering the page i programatically create an update panel which i pass to a thread. When this thread finishes it then updates the updatepanel on the main thread. public void test(object parameter) { Thread.Sleep(2000)...

Java:Get a value from a thread...?

How can return a variable from a thead (I have the threads handle too). Static variables will not work in this case. Update: Here is one twist, how can I do this without having to block and wait for the result? I need to be able to poll the created thread and kill it if it is hanging for too long (eg> 1 minute), then continue on in the ...

Best practices to turn a .NET class library into a multithreaded .NET class library

I have some C# class libraries, that were designed without taking into account things like concurrency, multiple threads, locks, etc... The code is very well structured, it is easily expandable, but it can benefit a lot from multithreading: it's set of scientific/engineering libraries that need to perform billions of calculations in ve...

How to only use a specific amount of threads in the threadpool at any given time

I found this question that was very useful in learning the basics of the ThreadPool. Now my questions lies in using the ThreadPool for a series of "tasks", like the Fibonacci class, but wanting to have at most n number of these tasks executing at any one time, or basically limiting these tasks as they execute in the ThreadPool to a ma...

Problem in CreateProcess function!

Hello all,I have my main application ,from my main application I will be calling another module(third party) to perform a small operation in my main application,when I call that module..it processes for a particular time say 5 sec.while its proccessing it shows the process in the commmand window with some information..now my main applica...

Deadlock in ruby code using SizedQueue

I think I'm running up against a fundamental misunderstanding on my part of how threading works in ruby and I'm hoping to get some insight. I'd like to have a simple producer and consumer. First, a producer thread that pulls lines from a file and sticks them into a SizedQueue; when those run out, stick some tokens on the end to let the...

Concepts and tools required to scale up algorithms

Hi, I'd like to begin thinking about how I can scale up my algorithms that I write for data analysis so that they can be applied to arbitrarily large sets of data. I wonder what are the relevant concepts (threads, concurrency, immutable data structures, recursion) and tools (Hadoop/MapReduce, Terracota, and Eucalyptus) to make this happe...

When to use recursive mutex?

I understand recursive mutex allows mutex to be locked more than once without getting to a deadlock and should be unlocked the same number of times. But in what specific situations do you need to use a recursive mutex? I'm looking for design/code-level situations. ...

need for a start method in java when using threads

Why do we need to run the thread through start method and not directly through the run method ? ...

Cross-thread event handling on non-UI object

I'm having a problem with handling an event on a different thread from where it is raised. The object that is handling the event is not an UI object however, so I can't use Invoke to execute the delegate and automatically switch to the UI thread for event handling. The situation is as following: I have an MDI application containing mult...

How to store/save Timer/Threads instances running in WCF service

I'm trying to make a simple scheduler service that will automatically send emails, etc. For now I have simple WCF service in which I create an instance of a timer, set a callback and do some work in the callback. Now this part works fine, with the callback being called and the work in it being done as expected. The issue is I need to m...

Lock Acquisition Order

Hi, With the following code, if a thread calls LoggingWidget.doSomething(), what is the order of lock acquisition that the thread has to go through? (i.e. does it get the Lock on LoggingWidget first, and then gets the lock on Widget ? ) public class Widget { public synchronized void doSomething() { } } public class LoggingWidg...