multithreading

Linux: Processes and Threads in a Multi-core CPU

Is it true that threads, compared to processes, are less likely to benefit from a multi-core processor? In other words, would the kernel make the decision of executing threads on a single core rather than on multiple cores? I'm talking about threads belonging to the same process. ...

Memory corruption when using boost::shared_ptr in a multithreaded environment

* glibc detected malloc(): memory corruption (fast): ** This is the error I get when, in a multithreaded environment, I execute this portion of code: /// Some declarations typedef boost::shared_ptr<Object> ObjectPtr; ObjectPtr getObject() { return ObjectPtr(new Object); } /// What is actually executed in a thread void executeWor...

Synchronizing sub-thread with main thread - not so obvious problem

To be honest, I'm a little bit lame when it comes to threading ;) So I'm asking for a little help. Let's assume, we have some kind of control on which we can draw some charts. There's also a method that draws a chart on this control. The problem is that the charting method has access only to one of the fields of the control and we need ...

How to differentiate when wait(long timeout) exit for notify or timeout?

Having this wait declaration: public final native void wait(long timeout) throws InterruptedException; It could exit by InterruptedException, or by timeout, or because Notify/NotifyAll method was called in another thread, Exception is easy to catch but... There is any way to know if the exits cause was timeout or notify? EDIT: This...

C# Unit Testing - Thread.Sleep(x) - How to Mock the System Clock

I have to test a method which does a certain amount of work after an interval. while (running) { ... // Work ... Thread.Sleep(Interval); } Interval is passed in as a parameter to the class so I can just pass in 0 or 1 but I was interested as to how to mock the system clock if this wasn't the case. In my test I'd like...

Do Threads Add A Lot Of Overhead To An App?

As my app matures, I find myself finding more and more uses for threads. By now I must have about 25 threads, all doing important things and working together in symphony. I notice however that my app is sitting around 15.5MB resident. Compared to the browser (+/-35MB) I feel pretty safe, but I do notice the resident size of my app ever...

Updating WPF control in "real time"

I'm writing an application which will display the current image seen by a camera and it needs to update the shown image in real time, or close to it. Essentially, I have a camera with which I can capture images and I need to capture one every, say, 1 second and display that image to the screen. Currently, my application has an Image co...

Determine user & system time used by a thread

We have a qthreads-based workflow engine where worker threads pick up bundles of input as they are placed on a queue, then place their output on another queue for other worker threads to run the next stage; and so on until all the input has been consumed and all the output has been generated. Typically, several threads will be running t...

Searching for a QObject

I'm working on a multi-threaded Qt application and would like to connect a signal in a thread with slot in another thread. My problem is that I only have the string used to set the QObject:objectName in the signaling thread that is defined in a project wide constants file. My overall goal is to avoid having to pass pointers to objects ...

optimizing bitmap loading by using aSyncTask.

I have been trying to optimize my single thread app which loads a bunch of tiles that makeup a large bitmap. The app was becoming very sluggish when it would load the new tiles into system memory. Im now looking trying to use Async Tasks for this purpose. The app detects which tile is in the top left in a method called by onDraw, creates...

In pthread, how to reliably pass signal to another thread?

I'm trying to write a simple thread pool program in pthread. However, it seems that pthread_cond_signal doesn't block, which creates a problem. For example, let's say I have a "producer-consumer" program: pthread_cond_t my_cond = PTHREAD_COND_INITIALIZER; pthread_mutex_t my_cond_m = PTHREAD_MUTEX_INITIALIZER; void * liberator(void * ar...

Events vs. Yield

I have a multithreaded application that spawns threads for several hardware instruments. Each thread is basically an infinite loop (for the lifetime of the application) that polls the hardware for new data, and activates an event (which passes the data) each time it collects something new. There is a single listener class that consolidat...

Strange crash on selecting a UITableView cell

I am getting an EXC_BAD_ADDRESS crash when selecting a table's cell which should push a new view on the navigation controller. Here is the stack trace (the CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION_ is always there): I strongly suspect the new code I have added to load the initial data the app needs in a separate thre...

Java ThreadPool usage

Dear StackOverflow, I'm trying to write a multithreaded web crawler. My main entry class has the following code: ExecutorService exec = Executors.newFixedThreadPool(numberOfCrawlers); while(true){ URL url = frontier.get(); if(url == null) return; exec.execute(new URLCrawler(this, url)); } The URLCrawler fetches the...

Basic multi-threading in C / C++ -- hints, advice, tutorial, some direction?

Hello all. I would like to learn how to build a multi-threaded application, but I don't even really know where to start. How do most people implement multi-threading? Do they use the boost library? Is there some other way to do it? (using standard C / C++) I understand the concept, but totally have no idea where to even start to actua...

Java synchronized blocks

Hi, I want to ask the following: If we have a method e.g. public void doSomething(){ synchronized(this){ //some code processing here } String temp = "init"; //instead of i++ synchronized(this){ //some other code processing here } } is this method equivalent to public synchronized void doSomething()? I mean, ...

Sending an exception from thread to main thread?

Hi I want to pass an exception from current thread(that thread isn't main thread)to main thread. Why?cuz I check my hard lock in another thread(that thread use timer for checking), and when HardLock is not accessible or invalid, I create an exception which is define by myself and then throw that exception. So that exception don't work we...

Stop a Java thread which calls an Oracle procedure

Hello, On a Spring/Hibernate web application, I'm using a Work Queue, built with Java Threads. The Threads's run() method calls an Oracle procedure, which can last a bunch of minutes/hours. All the Work Queue's threads are stored in a list. I would like to build an interface (JSP), where I could display a list of the running jobs, and ...

python multiprocessing does not work

I don't understand why this simple code # file: mp.py from multiprocessing import Process import sys def func(x): print 'works ', x + 2 sys.stdout.flush() p = Process(target= func, args= (2, )) p.start() p.join() p.terminate() print 'done' sys.stdout.flush() creates "pythonw.exe" processes continuously and it doesn't print a...

Why might System.Threading.dll be missing from Windows\Assembly?

I've various versions of the .NET Framework (versions 1.1 thru 4.0) installed on a remote machine running XP Professional. I've installed Reactive Extension too for good measure. I also have an application which works on my machine because it references System.Threading found here: C:\Program Files\Microsoft Reactive Extensions\redist\...