multithreading

Minimal latency objects pooling technique in multithread application

In the application we have something about 30 types of objects that are created repeatedly. Some of them have long life (hours) some have short (miliseconds). Objects could be created in one thread and destroyed in another. Does anybody have any clue what could be good pooling technique in the sense of minimal creation/destruction l...

Speed up loop using multithreading in C# (Question).

Imagine I have an function which goes through one million/billion strings and checks smth in them. f.ex: foreach (String item in ListOfStrings) { result.add(CalculateSmth(item)); } it consumes lot's of time, because CalculateSmth is very time consuming function. I want to ask: how to integrate multithreading in this kinda proces...

How much resources does consume sleeping thread?

I'm wondering, how expensive it is to have many threads in waiting state in java 1.6 x64. To be more specific, I'm writing application which runs across many computers and sends/receives data from one to another. I feel more comfortable to have separate thread for each connected machine and task, like 1) sending data, 2) receiving data,...

How to simultaneusly append several nodes to a XML file from different EXE instances, using Delphi

I have a command line tool, written in Delphi, which job is to insert a node in a XML file and then immediately exit. I need to make it possible several instances of the tool to be executed simultaneously and insert nodes to one and the same XML. To achieve this purpose I have introduced a simple file "mutex" - the tool creates one tem...

Viewing, pausing and killing threads in a running .Net application

I'm working on a .Net applications with multiple threads doing all sorts of things. When something goes wrong in production I want to be able to see which threads are running (by their managed name) and also be able to pause / kill them. Anyway to achieve this ? ...

Is it safe to get values from a java.util.HashMap from multiple threads (no modification)?

There is a case where a map will be constructed, and once it is initialized, it will never be modified again. It will however, be accessed (via get(key) only) from multiple threads. Is it safe to use a java.util.HashMap in this way? (Currently, I'm happily using a java.util.concurrent.ConcurrentHashMap, and have no measured need to im...

What is "thread local storage" in Python, and why do I need it?

In Python specifically, how do variables get shared between threads? Although I have used threading.Thread before I never really understood or saw examples of how variables got shared. Are they shared between the main thread and the children or only among the children? When would I need to use thread local storage to avoid this sharing...

Are locks unnecessary in multi-threaded Python code because of the GIL?

If you are relying on an implementation of Python that has a Global Interpreter Lock (i.e. CPython) and writing multithreaded code, do you really need locks at all? If the GIL doesn't allow multiple instructions to be executed in parallel, wouldn't shared data be unnecessary to protect? sorry if this is a dumb question, but it is somet...

Locking in C#

I'm still a little unclear and when to wrap a lock around some code. My general rule-of-thumb is to wrap an operation in a lock when it reads or writes to a static variable. But when a static variable is ONLY read (e.g. it's a readonly that is set during type initialization), accessing it doesn't need to be wrapped in a lock statement, ...

Any experiences with Intel's Threading Building Blocks?

Intel's Threading Building Blocks (TBB) open source library looks really interesting. Even though there's even an O'Reilly Book about the subject I don't hear about a lot of people using it. I'm interested in using it for some multi-level parallel applications (MPI + threads) in Unix (Mac, Linux, etc.) environments. For what it's wort...

What's the best way to pass data between concurrent threads in .NET?

I have two threads, one needs to poll a bunch of separate static resources looking for updates. The other one needs to get the data and store it in the database. How can thread 1 tell thread 2 that there is something to process? ...

Can a console app stay alive until it has finished its work?

I've just read up on Thread.IsBackground and if I understand it correctly, when it's set to false the Thread is a foreground thread which means it should stay alive until it has finished working even though the app have been exited out. Now I tested this with a winform app and it works as expected but when used with a console app the pro...

What are good sources to study the threading implementation of a XMPP application?

From my understanding the XMPP protocol is based on an always-on connection where you have no, immediate, indication of when an XML message ends. This means you have to evaluate the stream as it comes. This also means that, probably, you have to deal with asynchronous connections since the socket can block in the middle of an XML messa...

Why is my Java program leaking memory when I call run() on a Thread object?

(Jeopardy-style question, I wish the answer had been online when I had this issue) Using Java 1.4, I have a method that I want to run as a thread some of the time, but not at others. So I declared it as a subclass of Thread, then either called start() or run() depending on what I needed. But I found that my program would leak memory ov...

What is the coolest thing you have done with threads?

Just wondering ...

Unit testing a multithreaded application?

Does anyone have any advice for a consistent way to unit test a multithreaded application? I have done one application where our mock "worker threads" had a thread.sleep with a time that was specified by a public member variable. We would use this so we could set how long a particular thread would take to complete its work, then we cou...

Does it make sense to mix an RTOS and cyclic executive?

On a small embedded system project we have some code which we would like to run in a thread so we are electing to build in top of an embedded RTOS (eCos). Previously, we have used a cyclic executive in main() that drove tasks each implemented as a state machine. For some tasks we encountered problems where the task would need to be bro...

What is the best way to make a thread signal another thread in .NET?

I need to have a thread signal another if the user wishes to interrupt execution, however I'm unsure about how to implement the signaling/signal-checking mechanism. I wouldn't like to have a singleton in my project (like a global bool), but is there an alternative? In this thread people suggest proper structures for that in C++, but I d...

ASP.NET and Timers

Consider this code... using System.Threading; //... Timer someWork = new Timer( delegate(object state) { //Do some work here... }, null, 0, 60000); HttpContext.Current.Application["SomeWorkItem"] = someWork; Could this be dangerous? Caching a timer in the Application to perform some work in the background while yo...

Wait until any of Future<T> is done

I have few asynchronous tasks running and I need to wait until at least one of them is finished (in the future probably I'll need to wait util M out of N tasks are finished). Currently they are presented as Future, so I need something like /** * Blocks current thread until one of specified futures is done and returns it. */ public st...