multithreading

How to access a global variable from a worker thread

I have a vc++ 2005 dialog based application, where I use a worker thread to do some background processing. The worker thread is implemented as a global function in the dialog class I am able to access the variables of the dialog class inside the worker thread but I am not able to get some of their their values correctly inside the wor...

Threading Framework for Delphi 7 - any?

Hi, I'm looking for some threading framework to avoid writing it from scratches. Especially the tasks queuing and synchronization are what I need. I know OmniThreadLibrary which is great but is not compatible with D7. Any recommendations? ...

iPhone: Can't set object received from thread in NSMutableDictionary

I've got a thread (specifically an NSOperation) that runs to load some images for me for a scroll view when my main view asks for them. Any number of these NSOperations can be queued at once. So it goes with the filepath I give it and loads the image from the disk (as UIImages) and then sends the object back to my mainview by using perfo...

Data access synchronization between multiple threads.

Hi, I'm trying to implement a multi threaded, recursive file search logic in Visual C++. The logic is as follows: Threads 1,2 will start at a directory location and match the files present in the directory with the search criteria. If they find a child directory, they will add it to a work Queue. Once a thread finishes with the files in...

C# Receiving remote commands over TCP and invoking them on WinForm (Multithreaded)

I have a console that I want to use to invoke commands on a WinForm in another computer (I'm testing it through localhost though). When the form starts, it instantiates the CommandListener to receive commands over TCP. Whenever I attempt to instantiate it without a separate thread, the winform doesn't display at all, so I used "Initiali...

What can I do if two detached threads overlap each other? queue

Hi all, I'm not very 'up' on multi-threading, but I've been using detachNewThreadSelector in a couple of places to access data in a database. Unfortunately, on slower devices the first request may still be happening when I call the second... Which naturally causes a crash because both are calling the same method (which is obviously not ...

How can I implement cooperative lightweight threading with C on Mac OS X?

I'm trying to find a lightweight cooperative threading solution to try implementing an actor model. As far as I know, the only solution is setcontext/getcontext, but the functionality is deprecated(?) by Apple. I'm confused by why they did this; however, I'm finding replacement for this. Pthreads are not an option because I need cooper...

Porting a threaded C program to Python

As an exercise, I would like to port some of the functionality of a threaded C program (using pthreads) to Python. The C program spawns a thread to (almost) constantly iterate through certain directories, filling a data structure with their contents; these directories change crazy frequently (it's a mail queue). The main body of the ...

Windowsless application, threads and Invoke()

Let's suppose I have windowsless application: only NotifyIcon is presented. So I've created the only NotifyIcon that I need. But when I had a Form1 class I could use form1.Invoke(action) to perform actions from another thread. And what should I do now? UPD: this is an answer: we should Invoke() a menu itself if (mnuTrayMenu.InvokeRequi...

VC++ thread marshalling and COM : The application called an interface that was marshalled for a different thread

Hi, My VC++ 2005 Dialog based application initializes a COM object in the dialog class and uses it in the worker thread. I called CoInitialize(NULL) At the start of the application and the at the start of the worker thread. But when a COM method is called the error "The application called an interface that was marshalled for a differe...

What needs thread-safe code here?

Lets say we have an object that can be accessed by multiple threads and a global singleton handing out the object's reference, also accessible by multiple threads. class Book { private string title; public Book(string title) { this.title = title; } public string Title { get { return title; } } } class Bookstore...

C# memory model and non volatile variable initialized before the other thread creation.

Hi, I have a question related to the C# memory model and threads. I am not sure if the following code is correct without the volatile keyword. public class A { private int variableA = 0; public A() { variableA = 1; Thread B = new Thread(new ThreadStart(() => printA())).Start(); } private void printA() { System.C...

How to interrupt BufferedReader's readLine

I am trying to read input from a socket line by line in multiple threads. How can I interrupt readLine() so that I can gracefully stop the thread that it's blocking? ...

Threads interrupted when new activity is started. Android.

I have a slightly strange thing happening in my code atm, which I don't understand... I would much appreciate any input anyone may have. So here's the issue: In my main Activity I fire a Service, using an Intent, when a button is pressed on screen. The Service instantiates 22 Runnable objects each of which read data constantly from 22 s...

Java unlimited thread stops after some time

Hey fellows I hope you are doing well! So the problem is like this: I have a web server and some data storage kind of servers. What I need is synchronization between both the servers. Web servers are always up, and I try to keep the data servers up as long as possible. Both have mysql databases and I already have written scripts to syn...

New Thread for Instance of a Class (C#)

I have a form and several external classes (serial port, file access) that are instantiated by the form. 1) What's the simplest way to run an instance of an external class in its own thread? 2) Is the instance's thread automatically terminated when the form closes? ...

Method doesn't work when executed in a thread, but works otherwise - C#

I am a beginner in C# and I want to do the following: Thread t = new Thread(new ThreadStart(this.play)); t.Start(); This is the method play: private void play() { playSong("path\\to\\song.mp3"); } private static void playSong(String path) { mciSendString("open \"" + path + "\" type mpegvideo alias...

How to call a method that takes multiple parameters in a thread?

Hello Experts, I am building a C# Desktop application. How do I call a method that takes multiple parameters in a thread. I have a method called Send(string arg1, string arg2, string arg3) , I need to call this method using a thread called SendingThread. Can anyone help out with this? Any help will be much appreciated. ...

FJTask vs Future+Callables+ExecutorService

Objective: to make something like unpretentious map/reduce. There are many tasks they should be run in parallel, results added to the collection. If the task lasts longer than a certain time (eg 3 seconds) - cancel it. Which way is faster and more convenient? Share your experiences in building a "correct" multi-threading. thx in advance....

"Unable to evaluate expression because the code is optimized" when calling method from some thread

Hi all, I encounter a strage behavior in my application. I have a function: Load with try-catch blocks in class Task. When I'm calling it from the main thread: Task.Load() it runs OK. I created a thread which runs some method. when I call Task.Load() from the thread method I receive that message: "Unable to evaluate expression because...