multithreading

How to fill a byte array from multiple threads safely?

Is there a way to safely populate a byte array from multiple threads (e.g. first thread fills the first half, the second thread fills the second half using System.arraycopy) without synchronizing on the array itself using Java 6 or 7? The jsr166 related libraries only contain int arrays (AtomicIntegerArray, ParallelIntegerArray). ...

Wait for all worker threads to end

I've got following problem: I have monitoring class, which is running it's own thread that writes from queue into file (so the main application doesn't have to wait on IO). But, when main application thread ends (control flow runs after it's last line), the monitor thread ends too, even if it is still running (full queue). Is there any...

Threading in c#

How to call a function which takes two parameters using threading in C#? I have to call StartDNIThread(string storeID, string queryObject) from another function.I have to pass the two values.Both are string ...

How can I use Perl's system call to spawn independent threads?

I would like to call other Perl scripts in order to perform a contention test from with a main Perl script. Something like this currently works: system("perl 1.pl"); system("perl 2.pl"); exit; However, I would like to kick these off as independent threads running at the same time. I tried, based on my Google searches, doing somethin...

C#: Question regarding thread safety for member variables

Can someone explain why examples on threading will always make an object (specifically a member variable) static if it is to be accessed by multiple threads? My issue is that making the member variable static means that it will be shared among all other instantiations of the class. Sometimes I find that I would like multiple threads wit...

Logging multithreaded processes in python

I was thinking of using the logging module to log all events to one file. The number of threads should be constant from start to finish, but if one thread fails, I'd like to just log that and continue on. What's a simple way of accomplishing this? Thanks! ...

Parrallel reads from STL containers

It is safe to read a STL container from multiple parallel threads. However, the performance is terrible. Why? I create a small object that stores some data in a multiset. This makes the constructors fairly expensive ( about 5 usecs on my machine. ) I store hundreds of thousands of the small objects in a large multiset. Processing t...

Creating PDFs on the fly using AJAX & C#

I have a web page.There is a link to generate pdf reports.When the user clicks on the link the pdf generation process should start.Since the file size of the generated pdf is huge(>15Mb) the user cannot wait & thus has to proceed ahead with his other activities.That means the following simultaneous things would be happening now The PDF...

How Do I use LoadLibrary in COM Accross Multiple Threads?

Let's say that I have the following code that's run in one thread of a multi-threaded COM application: // Thread 1 struct foo { int (*DoSomething)(void ** parm); }; HMODULE fooHandle = LoadLibrary("pathToFoo"); typedef int (*loadUpFooFP)(foo ** fooPtrPtr); loadUpFooFP loadUpFoo; loadUpFoo = (loadUpFooFP)GetProcAddress(fooHandle, "f...

Good multithreading guides?

I'm looking for a good guide/tutorial on multithreading in C++ (and ideally in general). Can anyone point me to a good online resource? EDIT: I intend to familiarize myself with either the boost threading library or the one from Poco. ...

Is there a parallel processing implementation of HashMap available to Java? Is it even possible?

Searching for the magic ParallelHashMap class More succinctly, can you use multiple threads to speed up HashMap lookups? Are there any implementations out there that do this already? In my project, we need to maintain a large map of objects in memory. We never modify the map after it is created, so the map is strictly read-only. Howeve...

Spring Security Child Thread Context

Hi everyone, So I'm working on this Spring MVC application using Spring Security. I've been hitting a performance problem in some instances where my controller is taking way too long to respond. This is due to a processing method that can take a huge amount of data in to process, based on some user input. Now I've been tweaking the c...

Thread-safe invoke on NET CF

I have a background thread running that fires events, but how can I ensure a thread safe invocation of these events using NET CF? I would use ISyncronizeInvoke on the NET platform, but I can't find this on NET CF. I'm sure there are an equivalent available.... or? ...

Is my spin lock implementation correct and optimal?

I'm using a spin lock to protect a very small critical section. Contention happens very rarely so a spin lock is more appropriate than a regular mutex. My current code is as follows, and assumes x86 and GCC: volatile int exclusion = 0; void lock() { while (__sync_lock_test_and_set(&exclusion, 1)) { // Do nothing. This GCC ...

How can I return a value from a thread in Ruby?

If I have the following code : threads = [] (1..5).each do |i| threads << Thread.new { `process x#{i}.bin` } end threads.each do |t| t.join # i'd like to get the output of the process command now. end What do I have to do to get the output of the process command? How could I create a custom thread so that I can accomplish this?...

Why is this running like it isn't threaded?

I'm writing a script that will ping my ip range. Here's what I have so far: lines = `ipconfig`.split("\n") thr = [] ip_line = lines.detect { |l| l=~/Ip Address/i } matcher = /\d+\.\d+\.\d+\.\d+/.match(ip_line) if matcher.length > 0 address = matcher[0] address.sub!(/\.\d+$/,"") (1 .. 254).each do |i| xaddr = address + "...

SwitchToThread vs Sleep(1)

I'm wondering what's the actual difference between calling Thread.Sleep(1) and calling SwitchToThread (if we ignore that it's currently not exposed by the BCL). Joe Duffy mentions in his post that: "The kernel32!SwitchToThread API doesn't exhibit the problems that Sleep(0) and Sleep(1) do." (regarding the scheduler's behavior) Why...

C# Creating form from System.Threading.Timer tick fails

Hi When using System.Threading.Timer, and initializing a windows form on the timer's tick event, the form becomes unresponsive. Why is that, and how can I avoid it? This simple sample code shows the problem; the two first windows ("Original" and "Manual") works fine, but "Timer" becomes unresponsive at once. using System; using System...

Is lock free multithreaded programming making anything easier?

I only read a little bit about this topic, but it seems that the only benefit is to get around contention problems but it will not have any important effect on the deadlock problem as the code which is lock free is so small and fundamental (fifos, lifos, hash) that there was never a deadlock problem. So it's all about performance - is t...

Simple Deadlock Examples

Hello, I would like to explain threading deadlocks to newbies. I have seen many examples for deadlocks in the past, some using code and some using illustrations (like the famous 4 cars). There are also classic easily-deadlocked problems like The Dining Philosophers, but these may be too complex for a real newbie to fully grasp. I'm loo...