multithreading

Need a sample of single producer / single consumer pattern with .NET 4.0 new features

.NET for added new concurrency features under System.Collection.Concurrent and some synchronization classes. Is there any good sample for single producer - single consumer pattern using these feature ? (Actually I will add a circular buffer pattern to it if it already doesn't implement it as the shared buffer) ...

Premature exit from dispatch_asycn , Grand Central Dispatch..

Lets say i am running some code in dispatch async. .. is there a way to terminate the thread it creates before it completes? like when the user clicks cancel dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ //start doing something here.. break bofore it finishes? dispatch_async(dispatch_get_ma...

"Java DateFormat is not threadsafe" what does this leads to?

Everybody cautions regarding Java DateFormat not being thread safe and I understand the concept theoretically. But I'm not able to visualize what actual issues we can face due to this - say, I've a DateFormat field in class and the same is used in different methods in the class(formatting dates) in a multi-threaded environment. Will thi...

Thread problem in Windows 7 Phone

Hi I am working in windows 7 phone based app using silverlight. I have following methods in one of my UI classes, GameScreen.xaml. I am calling startTimer method in the constructor GameScreen. Problem is that when the updateTime method is called and timeLabel.Text = "Time left: 00 : " + time; line is executed, the program throws Una...

CreateRemoteThread() for function injection into another process

Hello everyone. I have a question about remote threads.I've read Mike Stall's article present here: http://blogs.msdn.com/b/jmstall/archive/2006/09/28/managed-create-remote-thread.aspx I would like to create a remote thread that executes a delegate in another process, just like Mike Stall does. However, he declares the delegate in the ta...

.net multi-threading

I'm writing dll which must run a function multiple times using different parameters, parallell to everything else. I've tried the following methods: Backgroundworkers MethodInvoker Threads etc What's the best way to do it? Update: I'm writing a dll, no GUI involved ...

Need to template for worker thread method

Hi, I need to design perfect worker thread method. The method must do the following: 1) extract something from queue (let's say a queue of string) and do something 2) stop and return when class is disposed 3) wait for some event (that queue is not empty) and do not consume cpu 4) run in separate thread Main thread will add string to...

Multithreading the pathfinding in a tower defense game

Hi, I'm making a tower defense game and I'm stuck at the multithreading of the pathfinding. If i don't make the pathfinding an NSInvocationOperation then there is an increasing pause in the rendering the more fiends and towers i have. However i cannot solve the "locking" issue. I get frequent crashes about enumerating my fiend NSMutable...

Java: Starting a cmd process that won't execute his job, but loaded into memory

Hello fellas! My problem is: I want to start a process via a thread and that process should execute his job. As far as I started the process, he remains into memory and does nothing until I close my main program. (like it was some kind of suspended) And only after exiting main program, this process is starting to do what he must. Di...

Simplest way to interrupt a thread that is blocked on running a process

I need to execute some commands via "/bin/sh" from a daemon. Some times these commands takes too long to execute, and I need to somehow interrupt them. The daemon is written in C++, and the commands are executed with std::system(). I need the stack cleaned up so that destructors are called when the thread dies. (Catching the event in a C...

How would I make a thread join on another thread but only wait for n seconds of CPU time?

otherThread.join( time ) appears to wait time in real milliseconds. I want to wait time in actual CPU time so that I can get consistent behavior within my application. I've done a quick look at ThreadMXBean but that doesn't quite seem to have what I wanted ( it tells me the threads actual CPU time, but offers no convenient way to wait ...

Can't safely lock a value of a ConcurrentDictionary

Hi, I'm having trouble locking on an item within a Collection - specifically a ConcurrentDictionary. I need to accept a message, look up that message within the Dictionary and then run a lengthy scan on that. As the program takes a lot of memory, after the scan the objects return true if they think its a good time to delete it (which I...

C# multithreading - updating the GUI with background events

Hi- I'm a newbie to C# and multithreading so I apologise if this is a duplicate question but being a novice it appears my question is slightly different to others I have read. My GUI runs in one (main) thread. It calls a background task (in a dll -- that I am writing too) that runs in a separate thread. The dll has NO knowledge of the ...

Python differences between running as script and running via interactive shell

I am attempting to debug a problem with a ctypes wrapper of a windows DLL and have noticed differences when I run tests via an interactive shell (python or ipython) and when I run the scripts non-interactively. I was wondering if there is any explanation for the differences I am seeing here? Specifically, when I interactively run a sim...

How to unit test this library?

I have an external library which has a method which performs a long running task on a background thread. When it's done it fires off a Completed event on the thread that kicked off the method (typically the UI thread). It looks like this: public class Foo { public delegate void CompletedEventHandler(object sender, EventArgs e); ...

Is it possible to pass a new parameter value into a running thread?

I've got a thread that currently updates a DataGridView on one tab (STATUS) of a TabControl. This thread currently functions quite well. What I would like to do is be able to update a small collection of controls on a different tab (SYNCH.) if the button to run the thread is clicked while on the SYNCH. tab. I considered passing an int...

Performance in multithreaded Java application

I want to understand performance in multithreaded environments. For that I have written a small test that I ran on my machine (quad-core Intel, Windows XP, Sun JDK 1.6.0_20), with surprising results. The test is basically a thread-safe counter that is synchronized using either the synchronized keyword or an explicit lock. Here is the co...

confused about python subprocess inside for loop

I am trying to automate some big data file processing using python. A lop of the processing is chained , i.e script1 writes a file , that is then processed by script2 , then script2's output by script3 etc. I am using the subprocess module in a threaded context. I have one class that creates tuples of chained scripts ("scr1.sh","scr2...

How to async add elements to Queue<T> in C#?

public void EnqueueTask(int[] task) { lock (_locker) { _taskQ.Enqueue(task); Monitor.PulseAll(_locker); } } So, here I'm adding elements to my queue and than threads do some work with them.How can I add items to my queue asynchronously? ...

kill boost thread after n seconds

I am looking for the best way to solve the following (c++) problem. I have a function given by some framework, which returns an object. Sometimes it takes just miliseconds, but on some occasions it takes minutes. So i want to stop the execution if it takes longer than let's say 2 seconds. I was thinking about doing it with boost threads...