multithreading

List shared between different threads in .NET

I have a static List in a class that will be accessed by different threads, each one adding, reading and removing its own unique item from the list. I would like to know if I have to worry about making this variable thread safe, as even though the same List object is shared between threads, they only modify their own unique items ...

HTTP Server Programming

Hello all, I'm attempting to write my own http 1.1 server, just for fun and learning about more about HTTP, sockets, and threading. I've gotten a good start i think with only delivering static pages (using c, which I would prefer to stay in for the time being). I have a test page I wrote a while ago and deliver it's ~50 files in 124ms...

Memory ordering issues

I'm experimenting with C++0x support and there is a problem, that I guess shouldn't be there. Either I don't understand the subject or gcc has a bug. I have the following code, initially x and y are equal. Thread 1 always increments x first and then increments y. Both are atomic integer values, so there is no problem with the increment ...

run threads in visual c++ 2010

i am using visual c++ 2010 can i run this code? what should i add to visual studio? ...

Starting and stopping operations in a thread-safe manner.

Hello! I have a simple class that looks a bit like this: @protocol Recorder @property(BOOL) isRunning; - (void) start; - (void) stop; @end And the method implementations: - (void) start { if (running) return; … running = YES; } - (void) stop { if (!running) return; … running = NO; } And I st...

Background tasks in Axis2 - Tomcat stack

I am working on a Java server side application that needs to provide a SOAP service. For this, we are using Axis2 and deploy in a Tomcat 6 installation. We have the following issue: we need to run a couple of background threads; one to periodically query another web service for changes in provided data and a second one to monitor and co...

how to handle this race condition?

hello, in my class i use a BackgroundWorker. at some point i need to cancel the asynchronous operation that can be in progress and start another one immediately. the code follows. one thing that i am not sure about is the race condition that can occur if the worker completes right before i assign my lambda to RunWorkerCompleted event. i...

Problem with a Java thread that captures sound card data

Hello I have a program which creates a thread that captures data from the soundcard at 48 KHz and writes it to a buffer for collection. The heart of the thread code is as follows .. public void run() { // Run continously for (;;) { // get data from the audio device. getSample(); } } // Read in 2 by...

Return an object by reference

I have a problem returning an object that was created in other thread. The situation is this, my app need to send some request to remote server and wait an answer. In the main thread (1) i have a method called SendAndWait. This method put a message in a message queue for be sent and wait for an answer. Another thread (2) send the message...

What is the difference between submit and execute method with ThreadPoolExecutor

I found there are two ways (submit and execute) to add a Runnable into a thread pool, what is the difference? ...

Close foreground thread gracefully on windows service stop

In my windows service I create one "parent" foreground thread that in turn spawns "child" threads using ThreadPool (which means they are background) to execute tasks. What is the best way to close foreground thread gracefully on windows service stop? Here is my current implementation (stripped out of task-specific logic): public parti...

Can Powershell Run Commands in Parallel?

I have a powershell script to do some batch processing on a bunch of images and I'd like to do some parallel processing. Powershell seems to have some background processing options such as start-job, wait-job, etc, but the only good resource I found for doing parallel work was writing the text of a script out and running those (PowerShe...

Sleeping in a Thread (C / POSIX Threads)

I am developing a multithreaded application that makes use of POSIX Threads. I am using threads for doing a periodical job and for that purpose I am using usleep(3) to suspend thread execution. My question is how can I cancel usleep() timer from the main thread, I tried pthread_kill(thread, SIGALRM) but it has a global effect which resul...

Thread-safe way to increment and return an integer in Delphi

In a single-threaded application I use code like this: Interface function GetNextUID : integer; Implementation function GetNextUID : integer; const cUID : integer = 0; begin inc( cUID ); result := cUID; end; This could of course be implemented as a singleton object, etc. - I'm just giving the simp...

Execute shell script in the background while a page is displayed on screen to the user in php

In my application, I am running a shell script but till the script completes executing the screen is blank. I am not able to display anything on screen. I want to display the log file to the user so till the log file is generated, i want the user to see some text content on the screen. I read previous questions posted where they say mul...

Efficient cache synchronization

Consider this public Object doGet() { return getResource(); } private Object getResource() { synchronized (lock) { if (cachedResourceIsStale()) { downloadNewVersionOfResource(); } } return resource; } Assuming that doGet will be executed concurrently, and a lot at that, and that downloadin...

run threads in c#

here is code for running threads in c# using System; using System.Collections.Generic; using System.Linq; using System.Text; using System; using System.Threading; namespace create_thread { class Program { public delegate void ThreadStart(); static void Main(string[] args) { Thread t=new...

Variable scope in multithreading, why my object reference is lost ?

Briefly under a single producer - single consumer scenario, I used a mutable object for synchronization and passing data and messages between producer and consumer. Shared buffer is a ConcurrentQueue of byte arrays. To implement a circular buffer and prevent heap fragmentation and frequent object swapping by GC I used a ConcurrentBag of ...

How to pass multiple parameters in thread in VB

I'm looking to pass two or more parameters to a thread in VB 2008. The following method (modified) works fine without parameters, and my status bar gets updated very cool-y. But I can't seem to make it work with one, two or more parameters. This is the pseudo code of what I'm thinking should happen when the button is pressed: Private ...

I need an idea for a program with threads

Hi there. This might sound funny but I got a homework and I can`t make any sense of it. The statement sounds like this: "Find the 10 largest numbers in an array of 100.000 randomly generated integers. You will use threads to compare 2 numbers. A daemon thread will print at regular intervals the progress and the number of unchecked in...