multithreading

ThreadPoolExecutor policy

I'm trying to use a ThreadPoolExecutor to schedule tasks, but running into some problems with its policies. Here's its stated behavior: If fewer than corePoolSize threads are running, the Executor always prefers adding a new thread rather than queuing. If corePoolSize or more threads are running, the Executor always prefers queuing a r...

How to wrap an asynchronous class to make it synchronous? Use NSRunLoop?

I'm currently working on an iPhone app and I have a library from a third-party that has asynchronous behavior but that I'd like to wrap with my own class and make it appear synchronous. The central class in this library, let's call it the Connection class, has several functions that have their ultimate result resolved when methods on ...

How Do I Choose Between the Various Ways to do Threading in Delphi?

It seems that I've finally got to implement some sort of threading into my Delphi 2009 program. If there were only one way to do it, I'd be off and running. But I see several possibilities. Can anyone explain what's the difference between these and why I'd choose one over another. The TThread class in Delphi AsyncCalls by Andreas Haus...

Why can't I use AsyncMethodCaller?

This is the first time I've used a thread that requires returning values to another class via a callback method. I've read up on it, and it seems that everyone is using the AsyncMethodCaller. However, even though I've added the necessary reference to my project, VS 2008 thinks it's undefined... what else could I possibly be doing wron...

Is it unwise to have a static method be used for security validation in ASP.net?

I have a static method like this public static string DoSomethingToString(string UntrustedString) { //parse format and change string here. return newString. } Since I know that multiple calls to: static int myInt=0; public static int AddNumber() { lock(someObject) { myInt++; } return myInt; } will return an ever increasing number (...

Is this java project idea practical? (Thread scheduler and Particle Swarm Optimization)

On a multicore box, the java thread schedulers decisions are rather arbitrary, it assigns thread priorities based on when the thread was created, from which thread it was created etc. The idea is to run a tuning process using pso that would randomly set thread priorities and then eventually reach optimal priorities where the fitness fun...

how to kill a thread which is waiting for blocking function call in Java?

I have a thread: Thread t = new Thread(){ public void run(){ ServerSocketConnection scn = (ServerSocketConnection) Connector.open("socket://:1234"); // Wait for a connection. SocketConnection sc = (SocketConnection) scn.acceptAndOpen(); //do other operation } }; t.start(); Lets sa...

How to implement SerialPort with thread/background worker C#?

I'm writing a class which would handle all the serial communications with a external device (i.e. reading and writing). The data is being streamed to the computer at 20Hz, and occasionally data is also written to the device. The class would then output valid data through an event to the main UI. I want to put this class in a separate thr...

Multi-threading guidelines: Can't remember my source

Hi, I'm trying to track down the source of a particular piece of coding advice I once read. I'm currently working with a class that has a lot of threading around a single shared resource, controlled by a mutex. I just spent a week trying to debug the damn code, because it's difficult to spot sub-functions which don't self-lock, and...

BeginInvoke error

HI, This quetion is in continuation to my question at this link. I wrote an application to compare the approach, used there, with other ways. While running the application in debug mode I got the error "Invoke or BeginInvoke cannot be called on a control until the window handle has been created." on the first BeginInvoke in method Upd...

Thread safety, lists, binding and WPF

I have a WPF ListView that is bound to a collection (List<T>). It is currently updated from the current thread which works ok. I want to move the logic for updating the list into a thread and I see some potential issues regarding thread safety and the binding of the list. Can I be assured that the binding will not be updated unless I ...

Trying to understand Threading in Ruby. Test Code doesn't work as expected, why?

So, I wrote a quick thread example for myself, using the ruby docs for thread: puts "Hello World" test = Thread.new do while true puts Time.now end end puts "Goodbye World" I would EXPECT this code to run forever, printing "Hello World", a few time stamps, goodbye world, and then a whole bunch of time stamps, until I manually break ...

Delegate.BeginInvoke Delay

Hi, Sometimes when BeginInvoke is invoked, it takes more than one second to execute the delegate method. What could be the reasons for the delay? I get this issue 1 or 2 times a day in an application which runs continuosly. Please help me. Thanks! ...

How to let Timer skip tick if the previous thread is still busy

Hey, I created a windows service, that is supposed to check a certain table in the db for new rows every 60 seconds. For every new row that was added, I need to do some heavy processing on the server that could sometimes take more than 60 seconds. I created a Timer object in my service, that ticks every 60 seconds and invokes the wante...

Java: Parallelizing quick sort via multi-threading

I am experimenting with parallelizing algorithms in Java. I began with merge sort, and posted my attempt in this question. My revised attempt is in the code below, where I now try to parallelize quick sort. Are there any rookie mistakes in my multi-threaded implementation or approach to this problem? If not, shouldn't I expect more tha...

Proper handling of GetLastError (and others) in a multithreaded context.

Is it correct to assume that GetLastError (and variants) are per-thread or is it per-process? The problems if it is per-process are somewhat obvious in multithreaded apps because there is no way to guarentee that no other Win32 calls were made between your failed call and GetLastError. Sometimes the value of GetLastError is important. ...

When to dispose of System.Threading.Task with child tasks?

I have a task that launches several child tasks. (e.g., Task A creates B,C,D,E,F). I also create a System.Threading.Timer to poll a database every 10 seconds to check if the scheduled item was cancelled by request. If it does, it sets CancellationTokenSource so that the task knows to cancel. Each sub-task, in this case B,C,D,E,F, wil...

Should this be a synchronized method?

I'm using TestNG to run tests in parallel and want to be careful about possible synchronization issues with helper classes and utilities. To my knowledge, each test is its own object, transparently created by the test runner. Thus, I don't need to worry about synchronizing anything non-static, since it would be an object created in a Thr...

How can I accomplish ThreadPool.Join?

I am writing a windows service that uses ThreadPool.QueueUserWorkItem(). Each thread is a short-lived task. When the service is stopped, I need to make sure that all the threads that are currently executing complete. Is there some way of waiting until the queue clears itself? ...

Why does my Ruby thread demo not use both cores?

Hopefully this screenshot will explain my question: a = Thread.new { loop {} } b = Thread.new { loop {} } a.join So how come both of my cores aren't maxed out? No matter how many threads I use, it's the same each time; the total CPU usage never seems to exceed 52%. >ruby -v ruby 1.8.6 (2010-02-04 patchlevel 398) [i386-mingw32] ...