multithreading

How do I implement a rate throttled TaskScheduler

I would like to limit the rate at which System.Threading.Tasks are run, so that only a set number of tasks are completed per second. I imagine I would need to Implement a TaskScheduler to do so but i am not sure how. Can any one give me an idea as to how to go about this. ...

One thread per client. Doable?

I'm writing a Java server which uses plain sockets to accept connections from clients. I'm using the fairly simple model where each connection has its own thread reading from it in blocking mode. Pseudo code: handshake(); while(!closed) { length = readHeader(); // this usually blocks a few seconds readMessage(length); } cleanup();...

wpf app crashes when BackgroundWorker is used

hello, my view model creates a BackgroundWorker in its constructor. BackgroundWorker updates the model's properties from its DoWork event handler. The code below is a contrived example (ViewModelBase is taken almost verbatim from the MVVM paper). public class MyViewModel : ViewModelBase { public int MyProperty { get ...

pfsockopen thread-safe?

I'm writing a PHP site which connects to a Java server to get data. It does this via a socket. To improve performance I'd like to use pfsockopen() to connect to the server, so a new connection (with costly handshake) doesn't have to be opened for every request. What I can't find in the documentation though, is this thread safe? If PHP i...

Trouble with Emacs pdb and breakpoints in multi-threaded Python code

I am running Emacs 23.2 with python.el and debugging some Python code with pdb. My code spawns a sibling thread using the threading module and I set a breakpoint at the start of the run() method, but the break is never handled by pdb even though the code definitely runs and works for all intents and purposes. I was under the impressi...

Delphi threading - which parts of code need to be protected/synchronized?

Hi, so far I thought that any operation done on "shared" object (common for multiple threads) must be protected with "synchronize", no matter what. Apparently, I was wrong - in the code I'm studying recently there are plenty of classes (thread-safe ones, as the Author claims) and only one of them uses Critical Section for almost every me...

Multithreading producer-consumer pattern using .Net TPL discussion

Firstly, my scenario: An application with data input, data processing and result aggregation. Input data can be huge so it is cut into batches. Batches are individual. Data processing becomes batch processing and is a relatively time-consuming procedure. Finally, each batch processing would result in a batch result. All batch results ar...

iphone ios running in separate thread

What is the best way to run code on a separate thread? Is it: [NSThread detachNewThreadSelector: @selector(doStuff) toTarget:self withObject:NULL]; Or: NSOperationQueue *queue = [NSOperationQueue new]; NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self ...

iphone building a view in a separate thread

I have a large modal view that pops up and it requires lots of other little views to be build, rendered and then added. I have been doing this asyncronisely by building the view parts aync and only performmingselectoronMainthread when necessary. This is all good unless the user wants to quit out of the view (using a close button) befor...

Howto wait work thread in the main Form?

Hi, after reading a few articles, I am still not sure I understand Multi-threading to solve my particular problem. I have a Main form which will start a background worker thread(worker). The worker thread will doing a While(!Stopping) infinity loop and will sleep at end of each iteration terminate by global Stopping object(Read only lo...

SwingWorker doesn't work as expected

I'm trying to find the differences between SwingWorker execute() vs doInBackground().So I have written this simple program to test the difference. public static void main(String[] args) { // TODO code application logic here for(int i=0;i<10;i++){ try { new Worker().execute(); } catch (Exception ex) {...

VB.NET Delegate doesn't work

In my application, I have a MainWindow with a ToolStripProgressBar and a ToolStripStatusLabel. This properties: Property ProgressBarPercantage() As Integer Implements BCSXPSearchTool.Presenter.IMainView.ProgressPercentage Get Return Me._progressbarpercentage End Get Set(ByVal value As Integer) Me._progressba...

Silverlight Sculpture generated application locking up on service calls (on some machines)

We have an application generated using the Sculpture software package. That means the project is roughly equivalent to the code in a Prism application. Part of their model is that all WCF Service calls are performed synchronously, but on background threads (actually they are async calls as well, but the Sculpture background thread metho...

How to locate a free/delete mismatch reported by Valgrind in a multithreaded program ?

Here is the Valgring report: ==14546== Thread 5: ==14546== Invalid free() / delete / delete[] ==14546== at 0x490555D: free (vg_replace_malloc.c:235) ==14546== by 0x3BF7EFAA8F: free_mem (in /lib64/tls/libc-2.3.4.so) ==14546== by 0x3BF7EFA581: __libc_freeres (in /lib64/tls/libc-2.3.4.so) ==14546== by 0x4802676: _vgw_freeres (v...

How can I ensure a determenistic result for this multithreading problem?

Consider the following test snippet: // act AutoResetEvent workDoneEvent = new AutoResetEvent(false); ThreadPool.QueueUserWorkItem(delegate { ProcessAndSignal(processor, workDoneEvent); }...

is there any difference if thread is waiting for monitor to be freed before synchronized block or if it calls wait()

I've read many docs about thread states, some of them tells that there is two different states: blocked (before synchronized) and wait (if calls wait), some others are telling that there is only one state: wait. Moreover, some docs telling that you should call notify() for every wait() and if you don't then threads waiting() will never b...

Thread Running in Web Page

If I browse to an asp.net web page that has the following in the page load, how long will the thread continue to run for after I close the browser? I would assume it would just finish on its own, but I'm not sure if it will terminate when the session ends, or something like that. protected void Page_Load(object sender, EventArgs e) { ...

Best way to report thread progress

I have a program that uses threads to perform time-consuming processes sequentially. I want to be able to monitor the progress of each thread similar to the way that the BackgroundWorker.ReportProgress/ProgressChanged model does. I can't use ThreadPool or BackgroundWorker due to other constraints I'm under. What is the best way to all...

Cleaning up code littered with InvokeRequired

I know that when manipulating UI controls from any non-UI thread, you must marshal your calls to the UI thread to avoid issues. The general consensus is that you should use test InvokeRequired, and if true, use .Invoke to perform the marshaling. This leads to a lot of code that looks like this: private void UpdateSummary(string text) {...

SDL: Is this safe to do in a multi-threaded program?

I have a thread that does the following: Initializes SDL Stores a pointer to the SDL_Surface Goes into a loop and waits for any mouse events and processes them In another thread there is a function that does the following: Gets the pointer to the SDL_Surface Does a SDL_LockSurface Manipulates the pixels Does a SDL_UnlockSurface Ca...