multithreading

Is there a way to determine how many runnables are in a newFixedThreadPool Queue?

I'm firing up Executors.newFixedThreadPool(100); in a main program and the producer is pumping in jobs faster than the consumers can keep up. Is there a way to see how many items are queued up in the underlying unbounded queue that the newFixedThreadPool uses? ...

How to better unit test Looper and Handler code on Android?

I use the android.os.Handler class to perform tasks on the background. When unit testing these, I call Looper.loop() to make the test thread wait for the background task thread to do its thing. Later, I call Looper.myLooper().quit() (also in the test thread), to allow the test thread to quit the loop and resume the testing logic. It's a...

WPF Window Implement ISynchronizeInvoke for use with System.Timers.Timer

Hi All The fact that the dispatch timer, updates on the UI thread, is convenient - with one problem... IT CAUSES THE UI TO FREEZE AT TIMES! As such, i would like to use the Timer in the System.Timers namespace, which will achieve the same thing except, that the UI will be more responsive as it updates from a different thread. System.T...

Invoke delegate on main thread in console application

In a Windows Application, when multiple threads are used, I know that it’s necessary to invoke the main thread to update GUI components. How is this done in a Console Application? For example, I have two threads, a main and a secondary thread. The secondary thread is always listening for a global hotkey; when it is pressed the secondary...

How to check a form is still 'alive'

I am loading a big treeview in a seperate thread. This thread starts at the load event of a form. All goes well, until an error occurs in the load event. When an error occurs I close the form and the thread that loads my treeview must be aborted. But I don't know how to do this. The problem is, that the form is closed and the thread is...

Threads usage in Application

Hello Team, Can any tell me that how many threads I can use in an application. I mean is the thread implementation usage is bounded to any fixed number? Can I use the same thread for more than one time? for example: public Thread td; td = new Thread(this); td.start(); Can I use the above thread in my same Application in the differe...

Threadsafe logging using streams

I have to implement a threadsafe logging mechanism in C++ under Windows and I want to use the streams library. I wanted to know if anyone could give me some advice regarding doing this and what would be the best way? The logging messages will most likely be a few lines long each time, so I'd probably need to write them to a buffer firs...

How to import the Python async module from a worker thread?

I'm using the GitPython package to access a Git repository from Python. This pulls in the async package. In async/__init__.py, the following happens: def _init_signals(): """Assure we shutdown our threads correctly when being interrupted""" import signal # ... signal.signal(signal.SIGINT, thread_interrupt_handler) _init...

C++ - basic thread question

Hello! I have a simple threading question - how should the following be synchronized? I have main thread and a secondary thread that does something only once and something - more that once. Basically: Secondary thread: { Do_Something_Once(); while (not_important_condition) { Do_Something_Inside_Loop(); } } I want t...

Do I need extra synchronization when using a BlockingQueue?

I have a simple bean @Entity Message.java that has some normal properties. The life-cycle of that object is as follows Instantiation of Message happens on Thread A, which is then enqueued into a blockingQueue Another thread from a pool obtains that object and do some stuff with it and changes the state of Message, after that, the objec...

Can two threads run two different methods at the same point of time?

class A { private synchronized f() { ... ... } private synchronized g() { ... ... } } If thread T1 is running f(), can thread t2 run g() at the same point of time, while T1 is still running f()? ...

C# Object Pooling With Interlocked.Increment

I have seen many good object pool implementations. For example: http://stackoverflow.com/questions/2510975/c-object-pooling-pattern-implementation. But it seems like the thread-safe ones always use a lock and never try to use Interlocked.* operations. It seems easy to write one that doesn't allow returning objects to the pool (just ...

How to use threads to replace looping a subroutine in perl/pdl

I have a perfectly good perl subroutine written as part of a perl module. Without going into too many details, it takes a string and a short list as arguments (often taken from terminal) and spits out a value (right now, always a floating point, but this may not always be the case.) Right now, the list portion of my argument takes two v...

What OS threads get used in Erlang’s abstract machine, BEAM?

I’ve begun studying Erlang and find the BEAM runtime environment fascinating. It’s commonly stated that in Erlang, processes belong to the language rather than the OS (meaning the runtime, meaning BEAM in this case). These are the lightweight, “green processes” that Erlang is getting famous for. It’s further stated (on page 5 of this pap...

C# using loop to start threads and pass parameters

In below sample code, I use lambda function to make 3 threads doing different things. My goal is make the thread count configurable, so I was thinking using a loop to start threads. But I always got in static function can't call non-static members error. Can the community help me or direct me to a tutorial? Thanks a lot! My Code: inter...

C++ Threads and Simple blocking mechanism?

I have a program in C++ that runs a bunch of threads to manipulate the same data. Each of these threads have a pointer to an object that is being manipulated, for example: thread1 and thread2 both have a pointer to object1 object1->addSomething() can be used by either thread1 or 2 and refer to the same object Now, these operations migh...

How should I debug-check an assumption that is valid in the future?

Sorry for the weird caption. Here's what I'm going to do: I'm in the client code, calling a method on the server. As a result, the server is going to send certain data to the client. I'd like to validate that these data have arrived within a second, which is necessarily the case unless something went seriously wrong. The code looks like...

Waiting for all tasks to finish using Task Parallel Library in .NET 4.0

Is there a shorter way to wait for multiple threads to finish? Maybe using ContinueWhenAll... but I don't want to run the rest of my code async. List<object> objList = // something List<Task> taskHandles = new List<Task>(); for(int i = 0; i < objList.Count; i++) { taskHandles.Add(Task.Factory.StartNew(() => { Process(objList[i]);...

python multi threading/ multiprocess code

In the code below, I am considering using mutli-threading or multi-process for fetching from url. I think pools would be ideal, Can anyone help suggest solution.. Idea: pool thread/process, collect data... my preference is process over thread, but not sure. import urllib URL = "http://download.finance.yahoo.com/d/quotes.csv?s=%s&am...

What if I don't join thread on "destruction" in release builds?

In many cases I have classes that act like active objects (have a thread). And to avoid access violations I always have to wait for join in the destructor. Which is usually not a problem. However imagine a release build with some bug (deadlock, livelock etc.) that causes join() not to return on time or at all, this would cause the enti...