multithreading

Wait for two threads to finish

If you have one main thread that starts two other threads. what is the cleanest way to make the primary thread wait for the two other threads? I could use bgndworker and sleep spinner that checks for both the bgnd workers's IsBusy, but I would think there's a better way. EDIT Some more requirements: The main thread has some other wor...

Define backgroundworker's RunWorkerCompleted with an anonymous method?

I Hope I used the right term What I'm aiming for is something like this (I realise it doesn't work that way): private bool someBool = false; BackgroundWorker bg = new BackgroundWorker(); bg.DoWork += new DoWorkEventHandler(DoLengthyTask); bg.RunWorkerCompleted += new RunWorkerCompletedEventHandler( ()=> { someBool = true; Log...

Is fprintf thread-safe?

Is fprintf thread-safe? The glibc manual seems to say it is, but my application, which writes to a file using single call to fprintf() seems to be intermingling partial writes from different processes. edit: To clarify, the program in question is a lighttpd plugin, and the server is running with multiple worker threads. Looking at the...

Good c++ lib for threading

I prefer a lib solely based on pthreads. What is a good c++ lib to for threading? ...

Simple C++ Threading

I am trying to create a thread in C++ (Win32) to run a simple method. I'm new to C++ threading, but very familiar with threading in C#. Here is some pseudo-code of what I am trying to do: static void MyMethod(int data) { RunStuff(data); } void RunStuff(int data) { //long running operation here } I want to to call RunStuff fro...

Threading paradigm?

Are there any paradigm that give you a different mindset or have a different take to writing multi thread applications? Perhaps something that feels vastly different like procedural programming to function programming. ...

C# Multi Thread Design Example

I am relatively new to C#/.Net. I'm developing a desktop application that requires multi threading. I came up with the following pattern below as a base. I was wondering if anyone could point out how to make it better in terms of coding, being thread safe, and being efficient. Hopefully this makes some sense. public abstract class Th...

C# Threading Patterns - is this a good idea?

I was playing with a project of mine today and found an interesting little snippet, given the following pattern, you can safely cleanup a thread, even if it's forced to close early. My project is a network server where it spawns a new thread for each client. I've found this useful for early termination from the remote side, but also from...

Does an asynchronous call always create/call a new thread?

Does asynchronous call always create a new thread? Example: If Javascript is single threaded then how can it do an async postback? Is it actually blocking until it gets a callback? If so, is this really an async call? ...

Creating/Opening Events in C++ and checking if they are fired

I have two threads that use an event for synchronization. In each thread they use the same call: ::CreateEvent( NULL,TRUE,FALSE,tcEventName ) The producer thread is the one that makes the call first, while the consumer thread makes the call last, so it's technically opening, not creating the event... I assume. But, when SetEvent is c...

Asynchronous vs Multithreading- is there a difference?

Does an asynchronous call always create a new thread? What is the between the two? EDIT: Does an asynchronous call always create or use a new thread? Wikipedia says: In programming, asynchronous events are those occurring independently of the main program flow. Asynchronous actions are actions executed in a non-blocking scheme, allo...

change boost thread priority

Im trying to change the thread priority in boost but im having no luck. Im getting a bad handle error (type 6) from the GetLastError function. I though native_handle() returned the handle for the thread? Any one know how to do this? void baseThread::applyPriority(uint8 priority) { #ifdef WIN32 if (!m_pThread) return; BOO...

Multithreading reference?

I am asking about a good reference for multithreading programming in terms of concepts with good examples using C++/C#? ...

What's the best way to fork/thread in PHP on Win?

I have a php script that checks for updates on many (thousands) of sites. On occasion (more frequently as the number of sites increases), I get an execution timeout on the update of one of these sites, and the whole script goes down the drain. The best idea I could come up with is to fork each update, so if it dies, the overall update j...

ThreadAbortException vs graceful event handle exit in C#.

When aborting the execution of a thread I'm always doubting between a graceful exit with an event handler like this: int result = WaitHandle.WaitAny(handles); if (result = WAIT_FINALIZE) FinalizeAndExit(); and using the event to signal the thread it must terminate or just handling the ThreadAbortException to finalize the thread... ...

WinForms multi-threaded databinding scenario, best practice?

Hi, I'm currently designing/reworking the databinding part of an application that makes heavy use of winforms databinding and updates coming from a background thread (once a second on > 100 records). Let's assume the application is a stock trading application, where a background thread monitors for data changes and putting them onto the...

Java Threading Tutorial Type Question

I am fairly naive when it comes to the world of Java Threading and Concurrency. I am currently trying to learn. I made a simple example to try to figure out how concurrency works. Here is my code: import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class ThreadedService { private ExecutorS...

Another way to solve the Dining Philosopher problem (need a point in the right direction)

Hello, for a programming assignment I have been asked to implement a solution to the Dining Philosopher problem. I must do so in two ways: Use the wait() and notifyAll() mechanism Using an existing concurrent data structure provided in the Java API I have already complete the first implementation. Which concurrent data structure is m...

python: how to send packets in multi thread and then the thread kill itself

Hi, I have a question. I'd like to send a continuous streams of byte to some host for certain amount of time (let's say 1 minute) using python. Here is my code so far: #! /usr/bin/env python import socket import thread import time IP = "192.168.0.2" PADDING = "a" * 1000 #assu...

How, if at all, do Erlang Processes map to Kernel Threads?

Erlang is known for being able to support MANY lightweight processes; it can do this because these are not processes in the traditional sense, or even threads like in P-threads, but threads entirely in user space. This is well and good (fantastic actually). But how then are Erlang threads executed in parallel in a multicore/multiproces...