multithreading

Mark a record as 'in use' to support multithreading

My (simplified) table consist of an Id int identity(1,1), File varchar(20), FileProcessed bit The logic is this: my application takes first (the order isn't important) record, which has FileProcessed bit set to false. Then it processes the file and sets the FileProcessed bit to true. Now, it can happen, that the first thread takes a ...

Java: Is it common practice to create a new Thread when a lock is held?

Hi all, I've got a question related but not identical to my first question ever here: http://stackoverflow.com/questions/2340114/java-what-happens-when-a-new-thread-is-started-from-a-synchronized-block Is it a common practice to create and start() a new Thread when you're holding a lock? Would that be a code smell? Basically I've g...

Updating DataGrid View in Multithreaded Environment

I have set of c++ dlls and a c# exe . My c++ dlls are multi-threaded and they put data into a Database. My c# exe uses Background worker . My c# exe gets these data to a Data table asynchronously. To achieve this I am using named Mutex. My problem is when I assign this Data Table to my grid view It is crashing. I am using delegates and B...

How do I find the processor on which my thread is running in C#?

How do I find the processor on which my thread is running in C#? ...

Running one thread on two cores

Do current architectures provide support for running the same single thread on multiple cores of a single system? What kind of issues would be involved in such a situation? ...

Is it possible to run the main QT program on a thread ?

I have a simple QT object. When I execute the code below the control is transfer to the QT object, but I would like to make the QT part work like a thread. int main(int argc, char *args[]) { gui *GUI; //// before call QApplication app(argc,args); GUI = new gui(); GUI->show(); ////i want to be able to do stuff...

addShutdownHook and setUncaughtExceptionHandler doesn't work as expected in java

I have a multi-threaded program, where I have one thread to watch over several threads. The functioning is designed like this: Main program does initiation and starts Watcher Thread, in void Main(), I have the line Runtime.getRuntime().addShutdownHook(new Thread(new ShutdownThread(), "Exit Listener")); When I don't start the watcher ...

.net: Is assigning an object reference atomic (i.e. thread-safe)?

Let's say I have some variable x (of type myClass), which is initially null and some assignment x = myObject occuring exactly once in some background thread. Is it guaranteed that x always contains either null or myObject when accessed from the main thread? Or is it possible that x contains some invalid data shortly? ...

Swing, Passive View and Long running tasks

I'm trying to implement a Passive View based gui system in swing. Basically i want to keep my view implementation (the part that actually contains swing code) minimal, and do most of the work in my Presenter class. the Presenter should have no dependency on swing and also should "run the show", i.e. tell the view what to do and not vice ...

Whats the best name for a wrapper that provides thread safe adding, removing, iterating over a collection to various objects?

This is a bit of weird scenario. I had a class that was quickly becoming a God class. It was doing WAY too much. Suddenly I had violated SRP. The class was responsible for X and Y and Z, oh and A, and B, don't forget C. So I decided to refactor it. The reason it got this big is because the class does a lot of work with a collection which...

Python's time.sleep - never waking up

I think this is going to be one of those simple-when-you-see-it problems, but it has got me baffled. [STOP PRESS: I was right. Solution was found. See the answers.] I am using Python's unittest framework to test a multi-threaded app. Nice and straight forward - I have 5 or so worker threads monitoring a common queue, and a single produ...

How do I control the access of multiple threads to a collection of objects?

I'm writing an application that displays a list of objects which the user can select and then view and edit the properties of through a PropertyGrid control. The object's properties are populated by time consuming process of extracting information from files through the use of a secondary thread. But I'd also like to allow the user to co...

Can I use waitForReadyRead in a QThread that belongs to the mainthread?

I have a QThread that contains a QUDPsocket (socket is member not local to QThread::run(), maybe I should change that from what I am reading). This QThread is instantiated in my QMainWindow class ie the GUI thread(I am not calling move to thread). Is it still safe to use waitForReadyRead or do I absolutly need to instantiate the QThread ...

wxPython: Threading GUI --> Using Custom Event Handler

I am trying to learn how to run a thread off the main GUI app to do my serial port sending/receiving while keeping my GUI alive. My best Googling attempts have landed me at the wxpython wiki on: http://wiki.wxpython.org/LongRunningTasks which provides several examples. I have settled on learning the first example, involving starting a wo...

Message Passing Arbitrary Object Graphs?

I'm looking to parallelize some code across a Beowulf cluster, such that the CPUs involved don't share address space. I want to parallelize a function call in the outer loop. The function calls do not have any "important" side effects (though they do use a random number generator, allocate memory, etc.). I've looked at libs like MPI...

Some commands hang my Ruby web app

I'm playing around with Rails & Sinatra, and I want to execute commands on the server. Those commands are entered from a form. The thing is, if I enter a command which expects input, my whole app hangs. Here's the code I'm using to execute them: @threads << Thread.new do Thread.current["buffer"] = "" puts "starting #{params[:com...

Two questions related to Ruby threads

First one: how can I create a Thread that doesn't start right away.If I use initialize without a block an exception gets raised. how can I subclass Thread, so that I may add some custom attributes, but keep the same functionality as the base Thread class? I'd also like to not have to use the initialize(&block) method for this. To bet...

How is simplest method to create threaded list in CakePHP?

I create table: id, name, thread_id The mainly thread has thread_id = 0, but their children has theard_id = id of parent, and how is the best and simplest solution to create list with children, and looks like: Category 1 Product 1 Product 2 Category 2 Product 3 etc... Maybe You have better solution for such a list? Sorry, for my eng...

Multi-thread object->object cache map in Java?

I want a collection in Java which: maps arbitrary Objects to Objects (not String or otherwise restricted keys only) will be used as a cache; if the key is not in the cache, a value will be computed (this doesn't have to be built into the collection) will be accessed from multiple threads simultaneously will never have items removed fro...

Process for converting python program into threaded application?

I have a code-base that I'm looking to split up and add to by using threading, however I'm relatively new on how to handle it. Please before reading further respect my wish of NOT just re-writing this code and tossing it back at me with the problem solved. I would much rather work the problem out by someone pointing me in the right dir...