multithreading

In a multi-threaded C++ app, do I need a mutex to protect a simple boolean?

I have a multi-threaded C++ app which does 3D rendering with the OpenSceneGraph library. I'm planning to kick off OSG's render loop as a separate thread using boost::threads, passing a data structure containing shared state in to the thread. I'm trying to avoid anything too heavyweight (like mutexes) for synchronization, as the render lo...

mdi app with multiple GUI threads

C# MDI application with separate GUI threads for each child in MDI is that possible ? For example if one of the child forms is blocked by some synchronous request it freezes the entire container ( MDI Parent ) and the other windows open also become in accessible. In general , is it possible to have more than one GUI thread in .net win...

c# locking

Hello, I am trying to prevent data races in a multihreaded server. My problem is the following: there is a List<RServer>, the type RServer is a class with several fields. Now, the server has several threads all running at the same time and they can modify both the List (adding more items) and the individual RServer instances (changing th...

Is MSMQ thread safe?

I have multiple processes monitoring an MSMQ queue. I want to do multi-step operations like first peek the message and then based on some criteria receive the message. A single message may pass the receiving criteria of multiple processes so that more than one process may try to receive the same message. Will these operations be thread s...

Thread local storage with __declspec(thread) fails in C++/CLI

I'm working on a project where we mix .NET code and native C++ code via a C++/CLI layer. In this solution I want to use Thread Local Storage via the __declspec(thread) declaration: __declspec(thread) int lastId = 0; However, at the first access of the variable, I get a NullReferenceException. To be more precise, the declaration is don...

What kind of behaviour causes an interrupted exception?

I'm relatively new to Threading in Java and I've noticed that everytime I use Thread.sleep() I have to catch InterrupetdException. What kind of behaviour causes this, and in simple applications where I have a monitor thread can I just Ignore the exception? ...

Detecting running in Main Thread in C# library

Hi! I'm creating a C# dll, which is going to be used by others developers in WinForms. For some reasons, I want to detect, if methods from this library, are called from Main (GUI) Thread and warn developer he has done such a thing (ie. in log file). Is there any reasonable way to detect calling method from main thread? Remember I have no...

Can anyone explain thread monitors and wait?

Someone at work just asked for the reasoning behind having to wrap a wait inside a synchronized. Honestly I can't see the reasoning. I understand what the javadocs say--that the thread needs to be the owner of the object's monitor, but why? What problems does it prevent? (And if it's actually necessary, why can't the wait method get ...

db4o client/server appears to only be able to process one query at a time?

We're evaluating db4o (an OO-DBMS from http://www.db4o.com). We've put together a performance test for client/server mode, where we spin up a server, then hammer it with several clients at once. It seems like the server can only process one client's query at a time. Have we missed a configuration switch somewhere that allows for this ...

What's the thread context for events in .Net using existing APIs?

When using APIs handling asynchronous events in .Net I find myself unable to predict how the library will scale for large numbers of objects. For example, using the Microsoft.Office.Interop.UccApi library, when I create an endpoint it gets events when phone events happen. Now let's say I want to create 1000 endpoints. The number of even...

How do you handle update refresh rate ?

How do you handle update refresh rate from your worker function to your UI ? Sending everything to the UI or maybe using a timer (from which side ? worker or UI ?) ...

.NET Web Service & BackgroundWorker threads

Hi Folks, I'm trying to do some async stuff in a webservice method. Let say i have the following API call: http://www.mysite.com/api.asmx and the method is called GetProducts(). I this GetProducts methods, i do some stuff (eg. get data from database) then just before i return the result, i want to do some async stuff (eg. send me a...

Please can someone give me a simple example of how to use System.Monitor in C# ?

I find System.Monitor very confusing, although I understand threading, locks, deadlocks, race conditions, dining philosophers and all that jazz. Normally I use a ManualResetEvent() to do inter-thread co-ordination, but I know that that's a heavyweight kernel object, and that System.Monitor (Enter/Pulse, etc.) is much more efficient. I'...

Aynchronous web server calls in Silverlight and maximum HTTP connections

Hi, I've read that Silverlight 2.0 imposes by design an asynchronous model when communicating with the web server. I haven't had a chance to experiment with Silverlight, but I assume that it uses a thread-pool to manage threads like in the .NET Framework. Now, since some browsers, most notably Internet Explorer, have an hard-coded limit...

What's the difference between Invoke() and BeginInvoke()

Just wondering what the difference between BeginInvoke() and Invoke() are? Mainly what each one would be used for. EDIT: What is the difference between creating a threading object and calling invoke on that and just calling BeginInvoke() on a delegate? or are they the same thing? Thanks ...

Delphi Multi-Threading Message Loop

Hi There, My application has several threads: 1) Main Thread 2) 2 Sub-Main Threads (each with Message Loop, as shown below), used by TFQM 3) n Worker Threads (simple loop, containing Sleep()) My problem is, when I close my application, the Worker Threads manage to exit properly, but 1 of the 2 Sub-Main Threads hangs (never exits) when ...

Thread vs ThreadPool

What is the difference between using a new thread and using a thread from the thread pool? What performance benefits are there and why should I consider using a thread from the pool rather than one I've explicitly created? I'm thinking specifically of .NET here, but general examples are fine. ...

Implementing wait for condition or cancel with threading

I am trying to implement the following functionality: class WeightResolver { WeightMonitor _source; bool _cancelled; Weight _threshold; public Cancel() { _cancelled = true; } public Weight Resolve(){ _cancelled = false; while(_source.CurrentWeight < threshold ) { if(_cancelled) throw ...

Difference between lock(locker) and lock(variable_which_I_am_using)

I'm using C# & .NEt 3.5. What is the difference between the OptionA and OptionB ? class MyClass { private object m_Locker = new object(); private Dicionary<string, object> m_Hash = new Dictionary<string, object>(); public void OptionA() { lock(m_Locker){ // Do something with the dictionary } ...

Violation reading location in std::map operator[]

I encountered a problem when running some old code that was handed down to me. It works 99% of the time, but once in a while, I notice it throwing a "Violation reading location" exception. I have a variable number of threads potentially executing this code throughout the lifetime of the process. The low occurrence frequency may be indica...