multithreading

java - question about thread abortion and deadlock - volatile keyword

Hello all, I am having some troubles to understand how I have to stop a running thread. I'll try to explain it by example. Assume the following class: public class MyThread extends Thread { protected volatile boolean running = true; public void run() { while (running) { synchronized (someObject) { ...

Is ThreadPool appropriate for this threading scenario?

I have a scenario that I'm trying to turn into a more responsive UI by pre-fetching some sub-elements of the results before they're actually required by the user if possible. I'm unclear on how best to approach the threading, so I'm hoping someone can provide some advice. Scenario There is search form (.NET rich client) that enable the...

Should I use .NET 4.0 Tasks in a library?

I'm writing a .NET 4.0 library that should be efficient and simple to use. The library is used by referencing it and using its different classes. Should I use .NET 4.0 Tasks tot make things more efficient internally? I fear that it might make the usage of the library more complex and limited since the users might want to decide for the...

Multi threading question..

I would like to invoke heavy duty method dowork on a separate thread and kill it if its taking longer than 3 seconds. Is there any problem with the following code? class Class1 { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main(string[] args) { Consol...

Writing to the same memory location, is this possible?

Consider the following: ThreadA and ThreadB are two threads writing diagnostic information to a common object which stores a list of diagnostic information. Is it possible for ThreadA and ThreadB to write to the same memory address at the same time? If so what would result? I'm using .NET however i'm not necessarily interested in one...

Do I need a semaphore for my thread in Android/Java?

Hello all, When running a thread in Android/Java: public void run() { while (running) { if (moreTasksToExec()) { task = getNextTask() task.exec(); } } } Is it OK to let it run and not using a semaphore to block while no work needs to be executed? I am only using one thread, so I need no ...

[Java] What toolkit to use to make more then one thread in painting? Swing, GWT, FX, Qt or what?

I want to write a multipaint application - a program that enables users from different computers to draw simultaneously on one image. What toolkit should I use? I've already discovered that Jambi is not appropriate in this case, because: Any number of threads can paint at any given time, however only one thread at a time can paint on a...

Android - Question on postDelayed and Threads

I have a question about postDelayed. The android docs say that it adds the runnable to the queue and it runs in the UI thread. What does this mean? So, for example, the same thread I use to create my layout is used to run the Runnable? What if I want it as an independent thread that executes while I am creating my layout and defining ...

pyGame in a thread

I want to use a pyGame program as a part of another process. Using the following code, pyGame doesn't seem to be processing events; it doesn't respond to the 'q' key nor does it draw the titlebar for the window. If go() is not run as a thread, it works fine. This is under OSX; I'm unsure if that's the problem or not. import pygame, thre...

Thread-safe initialization of static variables

I've been using this pattern to initialize static data in my classes. It looks thread safe to me, but I know how subtle threading problems can be. Here's the code: public class MyClass // bad code, do not use { static string _myResource = ""; static volatile bool _init = false; public MyClass() { if (_init == tru...

c# Thread issue using Invoke from a background thread

Hello - I've got thread, which processes some analytic work. private static void ThreadProc(object obj) { var grid = (DataGridView)obj; foreach (DataGridViewRow row in grid.Rows) { if (Parser.GetPreparationByClientNameForSynonims(row.Cells["Prep"].Value.ToString()) != null) Upda...

Lua and a little Multitasking

I'm working on a small project for the iPad and I simply want to run a script that will halt after certain function calls and then let me resume the script from the same place later on. In fact I only do 'threads' one at a time in a queue so it's really only multitasking between the iPhone OS and Lua. static int yield__ (lua_State *L) {...

fork system call cause segmentation fault

I have written a multithreaded program and the thread was implemented in such a way that as to fork a child process and through this child process several modules were loaded. During my testing at one time, i find process (running in solaris platform) aborts one time and it creates a segementation fault. On going through the dump file, ...

Why is CompareAndSwap instruction considered expensive?

Why is CompareAndSwap instruction considered expensive? I read in a book: "Memory barriers are expensive, about as expensive as an atomic compareAndSet() instruction." Thanks! ...

Printdialog in multithreaded wpf window thrown TargetInvocationException

I have designed a multithreaded app, which is starting most windows in an dedicated thread like this: Thread newWindowThread = new Thread(new ThreadStart(ThreadStartingPoint)); newWindowThread.SetApartmentState(ApartmentState.STA); newWindowThread.IsBackground = true; newWindowThread.Start(); However, if in one of those window-in-own-...

How can I guarantee that function returns a value before created secondary thread ended its work?

NSOperation *operation = /*some operation*/; [operationQueue addOperation:operation]; // … // Some work // … return Value; I want to get Value from function before operation ends. ...

Are threads from multiple processes actually running at the same time

In a Windows operating system with 2 physical x86/amd64 processors (P0 + P1), running 2 processes (A + B), each with two threads (T0 + T1), is it possible (or even common) to see the following: P0:A:T0 running at the same time as P1:B:T0 then, after 1 (or is that 2?) context switch(es?) P0:B:T1 running at the same time as P1:A:T1 In ...

Are events in WinForms fired asynchronously?

I recognize this may be a duplicate post, but I want to make sure I ask this question clearly and get an answer based on my wording. I have a collection of forms which inherit from a common visual element: MainVisualForm. This element provides me a way to know when the form is advancing of stepping backwards. What form comes next in th...

How do you notify a parent thread that all child threads have terminated?

I have a console app that I'm porting to WPF. The application has 3 worker threads, that are all joined to the main thread before some output results are printed to the screen. My understanding is that, if I try and do the same thing in a WPF application, the GUI will be blocked and will not be reponsive to the user. How then can I notif...

C++0x threading

With the advent of threading facilities in the STL for the new C++ standard (C++0x), will it be better to change existing code that is using POSIX threading or even Windows threading to use STL threading? ...