multithreading

Delphi - Is there any equivalent to C# lock?

I'm writing a multi-threaded application in Delphi and need to use something to protect shared resources. In C# I'd use the "lock" keyword: private someMethod() { lock(mySharedObj) { //...do something with mySharedObj } } In Delphi I couldn't find anything similar, I found just TThread.Synchronize(someMethod) method, ...

C# COM Cross Thread problem

Hi, we're developing a software to control a scientific measuring device. it provides a COM-Interface defines serveral functions to set measurement parameters and fires an event when it measured data. in order to test our software, i'm implementing a simulation of that device. the com-object runs a loop which periodically fires the e...

Physical Cores vs Virtual Cores in Parallelism

When it comes to virtualization, I have been deliberating on the relationship between the physical cores and the virtual cores, especially in how it effects applications employing parallelism. For example, in a VM scenario, if there are less physical cores than there are virtual cores, if that's possible, what's the effect or limits pla...

Is it possible to use instanceof when passing objects between Threads?

I've run into an issue where instanceof works, and then it doesn't. Going into details is difficult, but I think this might be the problem: Reading this: http://www.theserverside.com/news/thread.tss?thread_id=40229 (search for Thread.currentThread), it seems to imply that, even if the two objects are the same class, if you pass them be...

multi thread in c question

Does mutex guarantee to execute thread in order of arriving? that is, if, thread 2 and thread 3 arrive is waiting while thread 1 is in critical section what exactly happen after thread 1 exit critical section if thread 2 arrive at mutex lock before thread 3, thread 2 will be allowed to enter critical section before thread 3 ? or rac...

java thread - run() and start() methods

Please explain the output of the below code: If I call th1.run() ,the output is EXTENDS RUN>> RUNNABLE RUN >> If I call th1.start() , the output is : RUNNABLE RUN >> EXTENDS RUN>> Why this inconsistency . Please explain. class ThreadExample extends Thread{ public void run(){ System.out.println("EXTENDS RUN>>...

How can Swing dialogs even work?

If you open a dialog in Swing, for example a JFileChooser, it goes somewhat like this pseudocode: swing event thread { create dialog add listener to dialog close event { returnValue = somethingFromDialog } show dialog (wait until it is closed) return returnValue } My question is: how can this possibly work? As you can s...

A generic C++ library that provides QtConcurrent functionality?

QtConcurrent is awesome. I'll let the Qt docs speak for themselves: QtConcurrent includes functional programming style APIs for parallel list processing, including a MapReduce and FilterReduce implementation for shared-memory (non-distributed) systems, and classes for managing asynchronous computations in GUI applications. For ins...

Pass data from thread into Activity

Hi, I am want to pass data back from a Thread to Activity (which created the thread). So I am doing like described on Android documentation: public class MyActivity extends Activity { [ . . . ] // Need handler for callbacks to the UI thread final Handler mHandler = new Handler(); // Create runnable for posting f...

How do I get a thread safe print in Python 2.6?

print in Python is not thread safe according to these articles. A Python 3 work-around is offered in the latter article. How do I get a thread safe print in Python 2.6? ...

Catch unhandled exception of invisible thread

In my C++ application i use an activeX component that runs its own thread (or several I don't know). Sometimes this components throws exceptions. I would like to catch these exceptions and do recovery instead of my entire application crashing. But since I don't have access to its source code or thread I am unsure how it would be done. T...

Problem with thread after SCREEN_OFF in Android

I’m doing an application that listens to the android.intent.action.SCREEN_OFF in a Service (if that matter) and then it is supposed to wait a few seconds and launch an action, I’ve tried a timer schedule method, thread and handler postDelay method but all of them seems to fail, they are never executed on a device, it seems like it’s bein...

Accessing UI context from asynch task

I came across this android example that runs an AsyncTask from a UI thread. The class ExportDatabaseTask is declared and instantiated in the Activity, and apparently it is possible to reference the activity's UI context from the onPreExecute and onPostExecute events, like this: public class ManageData extends Activity { private Expo...

Reduce resource usage of an Idle task

I find that in uC/OS-II RTOS, there is an idle task that gets executed when no other task is ready to run. If an idle task can consume resources, how can we reduce it ? ...

Threading in Android

I am currently developing Android app, it needs download content from internet. I use thread to do that and then call runOnUiThread method to update GUI. I placed a refresh menu on it, if user tried to refresh the content, the download thread will be created and started. The problem is that how can I control the thread order, I need t...

Lowest context switch time

Which processor has the best context switch time ? ...

How to approach parallel processing of messages?

I am redesigning the messaging system for my app to use intel threading building blocks and am stumped trying to decide between two possible approaches. Basically, I have a sequence of message objects and for each message type, a sequence of handlers. For each message object, I apply each handler registered for that message objects type...

threading in c#

i am using this code: private void Form1_Load(object sender, EventArgs e) { } private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) { string response = serialPort1.ReadLine(); this.BeginInvoke(new MethodInvoker( () => ...

are simultaneous reads of a variable thread-safe?

Assuming that the variable isn't in any risk of being modified during the reads, are there any inherent problems in a variable being read by 2 or more threads at the same time? ...

How to terminate a thread which has spawned another thread which is sleeping?

I have a long running thread made from Thread.Start(). It spawns a background thread using QueueUserWorkItem which sleeps most of the time. Then the class-owner get disposed I call thread1.Join() but naturally it doesnt return because its child background thread is sleeping. What would be the right solution to gracefully terminate a th...