multithreading

Parallel Extension & locking - C#

I am reading the excellent article on Parallel extensions by Joe Albahari. He says, Leveraging multiple cores is easy for most server applications, where each thread can independently handle a separate client request, but is harder on the desktop — because it typically requires that you take your computationally intensive...

how to control Daemon thread?

I am writing a Java application in which i m writing a thread program to read a file. Every time the program is run it will create a thread and read the file. Its time consuming, I know the file will never change so I want to make a daemon thread which will read the file only once and store it in a String. The am facing several problems...

Would JavaScript fare any better had it been multithreaded

This is a follow up question to Is there a point to multithreading? If JavaScript were multithreaded, would it fare better than the existing system? Would multithreading with one UI thread and other tasks in different threads (background) bring in greater responsiveness and efficient usage of resources? Why did the designers of th...

When exactly do you use the volatile keyword in Java?

I have read "When to use 'volatile' in Java?" but I'm still confused. How do I know when I should mark a variable volatile? What if I get it wrong, either omitting a volatile on something that needs it or putting volatile on something that doesn't? What are the rules of thumb when figuring out what variables should be volatile in multith...

java synchronized on method Not working?

I'm experimenting Java Multi-Threading using synchronization on method comparing with Atomic variables (java.util.concurrent.atomic package). Below are the classes: // Interface ICounter.java public interface ICounter { public void increment(); public void decrement(); public int value(); ...

What is the mechanism behind startActivityForResult() in Android ?

I have an activity. In this activity I want to start another activity using startActivityForResult(). I understand that my basic activity is started within a process with a main GUI thread. But as far as I understand, startActivityForResult() is asynchronious which means that my new activity will be executed in a different thread. I ca...

Does using a lock has better performance than using a local (single application) semaphore ?

Does using a lock has better performance than using a local (single application) semaphore? I read this blog from msdn : Producer consumer solution on msdn and i didn't like their solution to the problem because there are always 20 elements left in the queue. So instead, i thought about using a Semaphore that will be available only in...

Multi-Threaded applicaiton has poor performace on a machine?

I have created a multi-threaded application that runs fine on every system except for one. The system is a windows 7 home edition setup. The 2 systems is running fine on are windows 7 Ultimate. Instead of each thread running independently, they seem to run in tandem. Also it runs really slow. It is really strange. I think the system is ...

How to call a method with a separate thread in Java?

let's say I have a method doWork(). How do I call it from a separate thread (not the main thread). ...

.NET Multithreading help...

I have an application I have already started working with and it seems I need to rethink things a bit. The application is a winform application at the moment. Anyway, I allow the user to input the number of threads they would like to have running. I also allow the user to allocate the number of records to process per thread. What I have ...

Java does javax.swing.Timer run on new thread?

I am using javax.swing.Timer to schedule and run events. But it seems to be freezing the GUI. Just wanted to know whether these events are run on a seperate thread or whether I have to do it myself. Thanks ...

Does a thread waiting on Windows Events need to get scheduled on CPU to wake up from sleeping?

It is best to describe my question in an example: We create a Windows Event handle by CreateEvent, with manualReset as FALSE. We create 4 threads. Ensure that they all start running and waiting on the above event by WaitForSingleObject. In the main thread, in a for loop, we signal this event 4 times, by SetEvent. such as: for (int i =...

WPF System.InvalidOperationException: The calling thread cannot access this object because a different thread owns it

In my Windows I have a TextBox which I like to update (text property) from another thread. When doing so, I get the InvalidOperationException (see title). I have found different links in google explaining this, but I still can't seem to make it work. What I've tried is this: Window1 code: private static Window1 _myWindow; private Mess...

Multi-threading: How to 'Lock' an Object by One or More Threads

I have one 'main' thread that creates an array of objects of class SlowData. These objects are relatively slow to manipulate with. This is why, when I initially load them, they are filled with stub data. Immediately after each object in the array is loaded, I can display the array in the UI. Parallel with that, I initiate the computatio...

thread in multi core processor

I have programm writting with C, and I want just only function in oher processor. Does anyone know how to be thread-distribution for multi-core processors work? Can a current thread running on the times one, sometimes on the other core, depending on how busy the nuclei are straight? Add Reply ...

How to guarantee thread-safety for overridden methods?

I've been struggling with this for 7 days now. Your insights will be greatly appreciated. Consider the framework code. final class Main { // assuming programmerCode was injected Interface inter = (Interface) programmerCode; inter.doProcess(); } interface Interface { void doProcess(); } abstract ProgramApp implements Interface { ...

Is it possible for a thread to Deadlock itself?

Is it technically possible for a thread in Java to deadlock itself? I was asked this at an interview a while back and responded that it wasn't possible but the interviewer told me that it is. Unfortunately I wasn't able to get his method on how to acheive this deadlock. This got me thinking and the only situation that I can think of is...

Java share a variable between two threads

Hi, I have two threads. One invokes the update method of a class that modifies a variable. Another invokes the update method of a class that reads the variable. Only one thread writes and one (or more) threads read that variable. What do I need to do in terms of concurrency, since I am new to multi-threading? public class A { publi...

Why do I need a memorybarrier

C# 4 in a Nutshell (highly recommended btw) uses the following code to demonstrate the concept of MemoryBarrier (assuming A and B were run on different threads): class Foo{ int _answer; bool complete; void A(){ _answer = 123; Thread.MemoryBarrier(); // Barrier 1 _complete = true; Thread.MemoryBarrier(); // Barrier ...

Invoke a method on the main thread without a WinForm control to call Invoke or BeginInvoke on.

I want to run an operation on a background thread. When it has completed I want to check for any errors that occurred and re-throw them on my original thread. I am using a backgroundworker. Throwing an exception in the RunWorkerCompleted event handler results in an unhandled exception - this makes sense if the eventhandler is running o...