multithreading

c++: Is checking current thread inside a function ok?

Is it ok to check the current thread inside a function? For example if some non-thread safe data structure is only altered by one thread, and there is a function which is called by multiple threads, it would be useful to have separate code paths depending on the current thread. If the current thread is the one that alters the data struc...

Updating an Image UI property from a BackgroundWorker thread.

In a WPF application I'm writing, I have a TransformedBitmap property which is bound to an Image object on the UI. Whenever I change this property, the Image is updated (and thus the image being displayed to the screen is updated). In order to prevent the UI from freezing or becoming unresponsive whilst I retrieve the next image, I'm a...

Is it possible to change parallelOptions.MaxDegreeOfParallelism during execution of a Parallel.ForEach

I am running a multi-threaded loop: protected ParallelOptions parallelOptions = new ParallelOptions(); parallelOptions.MaxDegreeOfParallelism = 2; Parallel.ForEach(items, parallelOptions, item => { // Loop code here }); I want to change the parallelOptions.MaxDegreeOfParallelism during the execution of the parallel loop to reduce or ...

Our SOLR instance seems to be single-threading and therefore not taking advantage of its multi-proc host

We are running SOLR 1.4.1 (Lucene 2.9.3) on a 2-CPU Linux host, but it seems that only 1 CPU is ever being used. It almost seems like something is single-threading inside the SOLR application. The CPU utilization is very seldom over 0.9 even under load. We are running on virtual Linux hosts and but our other apps in the same cluster a...

why ostringstream could not work well in multithreading environment

Maybe something is weird. When I use STL ostringstream class in my multithreading environment I found that the execution time of each thread increased linearly as the thread number increased. I don't know why this happened. I try to check the ostringstream source code but could not find any synchronization code. Are there some synchroniz...

Showing Progress Dialogs - What is the best approach for Office addins

I have a .NET based Excel addin that displays a custom toolbar in Excel. There are about 30 commands that can be executed through this toolbar. The commands are executed on the same (Excel) thread. I want to display progress dialog for some of the commands that take some time to execute for which I used a non-modal dialog. The dialog wo...

Using UML to detect potential race conditions in design

I'm battling a potential race condition in my application, which relies on multiple threads accessing a shared object to determine what their next logical operation should be. I certainly don't have a problem just scribbling stuff on a piece of paper or on the whiteboard, and using this to map out access to this shared object. However,...

Convert several Java methods to run as non-blocking threads?

Is it possible to convert a number of methods (defined in an interface and implemented in a class) to run as non-blocking threads? Certainly, i can wrap each single method in the run() method of a thread class. But perhaps there exists a more sophisticated way to warp several different methods in one step, i.e. by a single thread class...

Calling stopSelf() in Service while thread is running

Suppose I have code in the onStart() handler of my Service to launch a thread to do some stuff and then call stopSelf(). stopSelf() gets called before the thread finishes. What exactly happens? I've tested this out myself and my thread continues to execute until it is finished. Does Android hear the stopSelf() call, but postpone it u...

c# run 2 (or more) process in diffirent timing?

Hello, how to run different tasks in different process? in my case I will have 2 tasks one runs every 1 mint the other will run every 10 mints the point is each one is totally independent from the other how to make them work within the same program? cheers ...

Asynchronous threads in standard C++

Hi, I wonder how could I implement an asynchronous call in standard C++. I have a image/video processing program and I want to add another function/feature but I would like it to be run in a another thread or to be run asynchronously to the original thread. I just want to notify the main thread when something happened in this new threa...

How to create a thread safe EntityManagerFactory?

I'm working on a application that needs to do some database operations. I created a static variable for EntityManagerFactory and Intialized it in the method that gets called by the application if (emf == null){ emf = Persistence.createEntityManagerFactory("example"); } try { em = emf.cr...

thread Locking/unlocking in constructor/destructor in python

I have a class that is only ever accessed externally through static methods. Those static methods then create an object of the class to use within the method, then they return and the object is presumably destroyed. The class is a getter/setter for a couple config files and now I need to place thread locks on the access to the config fil...

How to synchronize multi-threaded calls to the same method

I have a method that is getting called from multiple threads. Each of the threads have their own instance of the class. What's the most straightforward way to synchronize access to the code? I can't just use lock(obj) where obj is an instance member, but would it be sufficient to just declare obj as static on the class? So all calls ...

Dynamic Method Invocation without Reflection

Does anyone knows how can I invoke method dynamically without reflection? I`ll try to specify my question below Suppose we have an interface IMyInterface and MyImplementation is an implementation of IMyInterface. Besides of that I have a generic proxy class MyProxy<T> where T : IMyInterface. In this proxy I wanna wrap all calls to all ...

python 2.6.x theading / signals /atexit fail on some versions?

I've seen a lot of questions related to this... but my code works on python 2.6.2 and fails to work on python 2.6.5. Am I wrong in thinking that the whole atexit "functions registered via this module are not called when the program is killed by a signal" thing shouldn't count here because I'm catching the signal and then exiting cleanly?...

IWebBrowser2 and multithreaded apartment?

Hi all, I am developing a Windows app with WebBrowser control (IWebBrowser2) embedded. Things look good if I initialize COM apartment as single threaded: CoInitialize(NULL); However, if I change it to be multithreaded: CoInitializeEx(NULL, COINIT_MULTITHREADED); then it starts to fail all over the places with return value of: ...

VB.NET: Threaded function call slower than calling function directly?

I have a function where I am performing a lot number of database operations inside a Sub. The operation when called directly like: ExecProcess() takes about 11 seconds to run. However, if I create a Delegate, and call the sub using BeginInvoke(), the very same process takes over 40 seconds to execute. Here's the threaded code: Prot...

Can someone explain the following strange function declarations?

std::thread f() { void some_function(); // <- here return std::thread(some_function); } std::thread g() { void some_other_function(int); // <- here std::thread t(some_other_function,42); return t; } ...

Queue not working with thread?

Hi, I have the following code that retrieves the first element off a queue only if it has at least 2 elements. For some reason, it's not polling the first element. However, if I add a print statement in there, it will print and poll. The method is in a thread, and there's another thread adding element to the queue, this thread reads f...