multithreading

How to debug Cross-Thread exceptions in .NET?

I was testing a program I am writing and I got this error message: Cross-thread operation not valid: Control 'lblStatus' accessed from a thread other than the thread it was created on The code is a bit massive and I am not sure which part is causing this error to post a smaller segment. However here is some info that might be of use. I...

Python multiple threads accessing same file

I have two threads, one which writes to a file, and another which periodically moves the file to a different location. The writes always calls open before writing a message, and calls close after writing the message. The mover uses shutil.move to do the move. I see that after the first move is done, the writer cannot write to the file a...

Access to SQL DB in multithread server app

In my server application I want to use DB (SQL Server) but I am quite unsure of the best method. There are clients whose requests comes to threadpool and so their processing is async. Every request usually needs to read or write to DB, so I was thinking about static method which would create connection, execute the query and return the r...

.NET: Mechanism for sync-ing long-running tasks

Problem description: you write a library which contains some algorithms/tasks which can take a long time to finish, for various reasons: computational, file system, network communication etc. You want to be able to: Send some progress information about the task (progress, activity logging etc.) Have a way to abort the task before comp...

Optimal CPU utilization thresholds

I have built software that I deploy on Windows 2003 server. The software runs as a service continuously and it's the only application on the Windows box of importance to me. Part of the time, it's retrieving data from the Internet, and part of the time it's doing some computations on that data. It's multi-threaded -- I use thread pool...

Coding/Designing a generic thread-safe limiter (i.e. limit the execution of X() to Y many times per second)

I'm planning to design a class to limit the execution of a function to given amount within the specified time, for example: Process max. 5 files in 1 second It should be thread-safe and performance hit should be minimal. How would you design such a class? I've got couple of ideas but none of them seemed right to me. Is there any ...

How to handle exceptions from a BackgroundWorker thread?

In a WPF app I have a sheduled database access task, periodically run by a timer and this task have been executed in a BackgroundWorker thread. When connection attempt failed I raise an exception by try_catch construction and I want to update a Status Bar text in a UI thread. Is there some prebuild event construction in a BackgroundWo...

A problem in c# using Threads and ListView.

I have a text filter where in the TextChanged event I launch a listview populate code this way: ThreadPool.QueueUserWorkItem(new WaitCallback(populate)); Then in the populate method I have code like this listView1.BeginUpdate(); listView1.Clear(); // rest of the code listView1.EndUpdate(); but the listView1.BeginUpdate() call giv...

How long is the delay between Control.Invoke() and the calling of its Delegate?

I have a code engine that plays long WAV files by playing smaller chunks in succession using the waveOutOpen and waveOutWrite API methods. In order to update my UI as the file plays, from the callback function as each buffer completes playing I Invoke a separate thread (because you want to do as little as possible inside the callback fu...

How do I declare an array created using malloc to be volatile in c++

I presume that the following will give me 10 volatile ints volatile int foo[10]; However, I don't think the following will do the same thing. volatile int* foo; foo = malloc(sizeof(int)*10); Please correct me if I am wrong about this and how I can have a volatile array of items using malloc. Thanks. ...

Java threads internals

I have been studying internals of Java for quite some time. I am curious to learn and understand how threading/locking takes place in Java. So, in order to access a synchronized method or a synchronized block, the thread has to acquire the lock on the object first. So, now, here is what I need a bit more light. So, whenever the thread...

How to properly access query-results created in background thread?

I want to execute a database query in a background thread. The OmniThread library will help me with all the thread stuff, but there is one thing I don't understand so far: Every thread needs a separate database connection. The background thread therefore creates the DB connection, creates the query and then executes it. Now I could acc...

Threading and pyfsevents

The module pyfsevents allows Python programs to utilize the Mac OS X FSEvents framework. One can register a path and a callback function, then call the listen() function, which blocks until a file system event happens in the registered path. pyfsevents.registerpath("/example", callback) pyfsevents.listen() I would like to use ...

How can I interrupt a synchronized statement in Java?

I have two threads that want to synchonize on the same object. Thead A needs to be able to interrupt Thread B if a certain condition has been fullfilled. Here is some pseudo-code of what the two threads do/should do. A: public void run() { while(true) { //Do stuff synchronized(shared) { //Do ...

In Qt, how do I query the state of a QMutex or a QReadWriteLock?

Hi, I'm using a QReadWriteLock in my application to guard access to a resource object. I'm using QReadLocks and QWriteLocks where I can, but sometimes I need a "long-lived" lock that crosses function boundaries. So sometimes I need to be able to query the state of the QReadWriteLock (or QMutex, same thing in this situation) because unl...

Using BackgroundWorker to update ListView

Hi all I am trying to update a listview from my backgroundworker. On the ProgressChanged event, I am passing back ProgressPercentage and a custom object called OperationInfo in the UserState object. OperationInfo has 4 properties: Operation(string), Success(boolean), Count(int), and AdditionalMessage(string) The below code updates my ...

Does this need explicit synchronization?

I have two threads, and I want to make sure I am doing the synchronization correctly on the LinkedBlockingQueue.. Is this correct? Or is the explicit synchronization on (messageToCommsQueue) not necessary? Declaration: private LinkedBlockingQueue<BaseMessage> messagesToCommsQueue; Method one: private void startOperationModeSta...

What is the C# equivalent of MsgWaitForMultipleObjects?

I have a Windows Form with a ListView in Report Mode. For each item in the view, I need to perform a long running operation, the result of which is a number. The way I would do this in native win32 is to create a worker thread for each item (naively; of course I won't create an unbounded number of threads) and then MsgWaitForMultipleOb...

How can I code a server/client video and audio streaming application?

Hi guys, I have to create a client/server system to stream video and audio. It would be very simple. Like youtube style. The server should attend clients providing a list of medias first and waiting the choice of each client to start streaming the media. Until create a socket and showing a simple list I'm on it ;) But I don't know which ...

After FileSystemWatcher fires - Thread Pool or Dedicated thread?

I am about to implement the archetypal FileSystemWatcher solution. I have a directory to monitor for file creations, and the task of sucking up created files and inserting the into a DB. Roughly this will involve reading and processing 6 or 7, 80 char text files that appear at a rate of 150mS in bursts that occur every couple of second...