multithreading

Keeping a thread alive in a C# application

Possible Duplicate: Locking main() thread Hello, Below you'll find my code, Main calls two threads, one initiates an event handler that returns the values of registry keys after they have been changed. The other sets up a timer which writes the changes to an XML file every few minutes. Basically I'm looking to run the write ove...

Java - why are wait() and notify() declared on Object Class?

Hi Experts, Please define why the wait() and notify() methods are in Object class and not in Thread class? Thanx ...

Is ConcurrentHashMap.get() guaranteed to see a previous ConcurrentHashMap.put() by different thread?

Is ConcurrentHashMap.get() guaranteed to see a previous ConcurrentHashMap.put() by different thread? My expectation is that is is, and reading the JavaDocs seems to indicate so, but I am 99% convinced that reality is different. On my production server the below seems to be happening. (I've caught it with logging.) Pseudo code example...

C# -Threading help for beginner

I want to run three threads (i) one should append strings into a file.(ii) The other thread should remove special characters from the written stream.(iii)The third thread should sort the words in ascending order.How could i do it in a thread safe(synchronized) manner ? I mean Thread 1 sample.txt Apple Ma#22ngo G@ra&&pes Thread 2 (a...

iPhone - return from an NSOperation

Hi I am using a subclass of NSOperation to do some background processes. I want the operation to be cancelled when the user clicks a button. Here's what my NSOperation subclass looks like - (id)init{ self = [super init]; if(self){ //initialization code goes here _isFinished = NO; _isExecuting = NO; } re...

C#: How to test a basic threaded worker class

I'm dipping my toes in how to test multi-threaded stuff, but not quite sure how to get started. I'm sure I will figure more stuff out easier if I could just get stuff going, so I was wondering if someone could help me write an NUnit test case for this simple class: class Worker { public event EventHandler<EventArgs> Done = (s, e) =>...

Can a static class be instantiated more than once within a single process?

Can a single process with multiple threads cause a static class to be created more than once? If I just need a simple construct can I use a static class, or do I have to resort to a singleton? ...

java: Difference between thread's context class loader and normal classloader

What is the difference between a thread's context class loader and a normal classloader. That is, if Thread.currentThread().getContextClassLoader() and getClass().getClassLoader() return different class loader objects, which one will be used? ...

Lock before reading a global string?

I have class than spins off a backgroundworker to do some processor intensive stuff. The background worker reads a few strings that are declared globally for the whole class... do I need to lock around those strings? The backgroundworker never write the strings, they simply represent some directory locations that are set in the construct...

C# .. Asynchronous Sockets .. where is the State Object Stored?

Hi all, A simple question really, but one where I cannot find any anwsers too. When I execute an Asynchronous Socket operation, such as : socket.BeginSend ( new byte[]{6}, // byte[] | buffer 0, // int | data to send buffer offset 1, // in...

.NET End Invoke / Post Operation Completed

My question involves async operations in VB .NET. Given the following: Delegate WorkerDelegate(Byval asyncOp As AsyncOperation) Public Sub StartWork() Dim worker as new WorkerDelegate(AddressOf DoWork) Dim asyncOp as AsyncOperation = AsyncOperationManager.CreateOperation(New Object) // begin work on different th...

Thread.VolatileRead Implementation

I'm looking at the implementation of the VolatileRead/VolatileWrite methods (using Reflector), and i'm puzzled by something. This is the implementation for VolatileRead: [MethodImpl(MethodImplOptions.NoInlining)] public static int VolatileRead(ref int address) { int num = address; MemoryBarrier(); return num; } How come t...

Python Threads do not run in C++ Application Embedded Interpreter

hi, I have a C++ application which uses embedded python interpreter with the Python C API. It can evaluate Python files and source code with PyRun_SimpleFile and PyObject_CallMethod. Now I have a python source code which has a worked thread which subclasses threading.Thread and has a simple run re-implementation: import time from thre...

Out of memory on _beginthreadex

I currently debug a multi threaded application, which runs without errors until some functions where called about 2000 times. After that the application stops responding, which I could track down to _beginthreadex failing with an out of memory error. When examining the Application in ProcessExplorer I can see a growing number of thre...

How to directly access the UI thread from the BackgroundWorker thread in WPF?

I'm creating a backup utility in WPF and have a general question about threading: In the method backgroundWorker.DoWork(), the statement Message2.Text = "..." gives the error "The calling thread cannot access this object because a different thread owns it.". Is there no way for me to directly access the UI thread within backgroundWorke...

@synchronized() and NSLock differences

Hi there, I have a block of code that is accessed frequently and from either the main thread or several other background threads. I need to ensure that this code only gets processed one at a time. I'm currently using a @synchronized(self) { } block but I'm not sure if that's providing the correct protection. How does it differ from an ...

Does AutoResetEvent.WaitOne() frees a slot in the thread pool?

I am trying to synchronize an asynchronous method. The main advantage of the async version is that it frees a slot in the thread pool. I would like to keep this advantage in my sync version. When I use AutoResetEvent.WaitOne() it is equivalent to a Thread.Sleep() in terms of thread pool usage? ...

Safety of Interlock.Exchange and Garbage Collection

I have an object that I am accessing from two threads. One thread calls a long-running member function on the object that returns a value. The second thread updates the object used to produce that value. I if I call Interlock.Exchange to replace the object from the second thread while the first thread is executing: 1. Will the old th...

Multithreaded application in Java?

I haven't worked with Java threads in several years so I have a very basic question about multithreading. I'm writing a java package that will be called by another language (matlab). Matlab is able to instantiate a Java class and run java code. I want to be able to: Start multiple threads Get a list of all running threads Stop a g...

How to get the maximum outbound requests when parellellizing asynchronous calls?

Analysing the code below in action through Fiddler, I realized that using Parallel Extensions I can get at maximum 2 outbound requests: new string[] { "http://stackoverflow.com", "http://superuser.com", "http://serverfault.com", "http://stackexchange.com" } .AsParallel() .Select(a => Http...