multithreading

Main thread's NSRunLoop being referenced in a secondary thread

Hi all, I was just recently futzing about with a sample application trying to get my head completely wrapped around NSRunLoop. The sample I wrote created a simple secondary thread via NSOperation. The secondary thread does a few tasks such as process an NSTimer and also some rudimentary streaming with NSStream. Both of these input sourc...

How can I correct the error "accessed from a thread other than the thread it was created on"?

This following code gives me the error below . I think I need "InvokeRequired" . But I don't understand how can I use? Cross-thread operation not valid: Control 'listBox1' accessed from a thread other than the thread it was created on. The code: using System.Collections.Generic; using System.ComponentModel; using System.Data; usin...

Remote Locking

I am designing a remote threading primitive protocol. Currently we only needs mutexes (i.e. Monitors) and semaphores. The main idea is that there doesn't need to be a central authority - the primitives should be orchestrated amongst the peers that are interested in them. I have bashed a few ideas around on paper and in my head for a few...

Threading in Objective-C

is there Thread in Objective c. if there how it is declare and use. if anybody know using multithreading in Objective -c ..pls share with me .. thanks and regards .. by raju.. ...

LoaderLock was detected in multithreaded C# application

Hello, I am writing a WinForms application in C#. At one point in the application, I spawn a new STA thread (create thread, then SetApartmentState) that creates a new form and then shows it with plain old Show(). The form itself contains only a docked DataGrid whose DataSource points to a DataTable retrieved from a newly open SqlConnect...

Is there a .Net equivalent to java.util.concurrent.Executor ?

Hello, Have a long running set of discrete tasks: parsing 10s of thousands of lines from a text file, hydrating into objects, manipulating, and persisting. If I were implementing this in Java, I suppose I might add a new task to an Executor for each line in the file or task per X lines (i.e. chunks). For .Net, which is what I am usi...

Swing: Problem distinguishing between user-induced and automatic components resizing (Writing a custom LayoutManager).

Hello! I'm trying to write an own layout manager. Components must be placed and sized relative to each other. This means: when the user drags or resizes an component, some other components (but not the one altered manually by user) have to be altered. Swing tells the layout manager to layout the components every time when some of them...

Best Data Structure for this Multithreaded Use Case: Is Intrusive List good?

I need to design a data structure that supports the following operations: search element in the data structure based on a key that is an interval. For example the value within interval 1-5 may be 3, from 6-11 may be 5 and so on. The intervals are contiguous and there is no overlap between them. find previous and next interval - this i...

How do I specify the equivalent of volatile in VB.net?

I'm attempting to write a lock-free version of a call queue I use for message passing. This is not for anything serious, just to learn about threading. I'm relatively sure my code is correct, except if the instructions are re-ordered or done in registers. I know I can use memory barriers to stop re-ordering, but how can I ensure values ...

Why is there no autorelease pool when I do performSelectorInBackground: ?

I am calling a method that goes in a background thread: [self performSelectorInBackground:@selector(loadViewControllerWithIndex:) withObject:[NSNumber numberWithInt:viewControllerIndex]]; then, I have this method implementation that gets called by the selector: - (void) loadViewControllerWithIndex:(NSNumber *)indexNumberObj { NSAu...

Join 2 'threads' in javascript

If I have an ajax call off fetching (with a callback) and then some other code running in the meantime. How can I have a third function that will be called when both of the first 2 are done. I'm sure it is easy with polling (setTimeout and then check some variables) but I'd rather a callback. Is it possible? ...

Which Java thread is hogging the CPU?

Let's say your Java program is taking 100% CPU. It has 50 threads. You need to find which thread is guilty. I have not found a tool that can help. Currently I use the following very time consuming routine: Run jstack <pid>, where pid is the process id of a Java process. The easy way to find it is to run another utility included in the ...

What are some strategies to unit test a scheduler ?

This post started out as "What are some common patterns in unit testing multi-threaded code ?", but I found some other discussions on SO that generally agreed that "It is Hard (TM)" and "It Depends (TM)". So I thought that reducing the scope of the question would be more useful. Background : We are implementing a simple scheduler that g...

How to get the stack size of an existing .NET thread

I want to find out the stack size of .NET thread pool threads in CLR 4.0. Any ideas? Nick ...

WCF:: ServiceHost: Oddity...Still alive even if thread is dead?

Hello, a new member here. Nice to see such a neat community. After a bit of research, I decided to use WCF in my application to do inter process communication, so I am using the NetNamedPipeBinding binding. The ServiceHost hosting application is not a dedicated server, so it has to spawn the ServiceHost via a thread. So far so good. S...

How many CRITICAL_SECTIONs can I create?

Is there a limit to the number of critical sections I can initialize and use? My app creates a number of (a couple of thousand) objects that need to be thread-safe. If I have a critical section within each, will that use up too many resources? I thought that because I need to declare my own CRITICAL_SECTION object, I don't waste kerne...

Help reviewing the following code, is it thread safe?

private static Callback callback; public Foo() { super(getCallback()); } private static Callback getCallback() { callback = new Callback(); return callback; } Constructor Foo() can potentially be called from multiple threads. My concern is with the private static field 'callback' and the static method 'getCallback()'. A...

How can I get CPU usage and/or RAM usage of a *THREAD* in C# (managed code)?

I know how to get CPU usage and memory usage for a process, but I was wondering how to get it on a per-thread level. If the best solution is to do some P-Invoking, then that's fine too. Example of what I need: Thread myThread = Thread.CurrentThread; // some time later in some other function... Console.WriteLine(GetThreadSpecificCpuUs...

C# multi-threaded unsigned increment

I want to increment an unsigned integer from multiple threads. I know about Interlocked.Increment, but it does not handle unsigned integers. I could use lock(), but I would rather not if possible for performance reasons. Is it thread safe just to increment it in the normal way? It would not matter if the occasional increment got lost,...

Writing a starter program which aborts hanging programs

I have a script which needs to periodically start programs out of a array with program names via Perl on Linux. The problem is that from time to time one of the programs takes too long/hangs and needs to be aborted. Currently I am starting the program using qx/$cmd/ in a seperate thread which reads from a shared start queue. The main t...