multithreading

EventWaitHandle behavior for pthread_cond_t

I've recently seen the light of EventWaitHandle's powerful behavior in C# and decided to move some functionality in a sister application to do the same. The only problem is that the sister app is written in C. No big deal, I'm using pthreads, which have a pthread_cond_t datatype that allows for signalling. My only question is, is it pos...

Is Windows' rand_s thread-safe?

Just as in title. Is suspect it is, but I couldn't find it anywhere explicitly stated. And for this property I wouldn't like to rely on speculations. ...

Are there any frameworks for handling database requests in swing applications?

I believe any programmer who has been dealing with database requests in a gui application has run into some or all of the following problems: Your GUI freezes because you call database layer from within the event dispatch thread When you have multiple windows/panels/jframes where user can start a db request your performance degrades be...

How does Multiple C++ Threads execute on a class method

Hello, let's say we have a c++ class like: class MyClass { void processArray( <an array of 255 integers> ) { int i ; for (i=0;i<255;i++) { // do something with values in the array } } } and one instance of the class like: MyClass myInstance ; and 2 threads which call the processArray method o...

Implementing multithreading in C# (code review)

Greetings. I'm trying to implement some multithreaded code in an application. The purpose of this code is to validate items that the database gives it. Validation can take quite a while (a few hundred ms to a few seconds), so this process needs to be forked off into its own thread for each item. The database may give it 20 or 30 items ...

When to use thread pool in C#?

I have been trying to learn multithreaded programming in C# and am confused about when it is best to use the thread pool vs. create my own threads. One book recommended using the thread pool for small tasks only (whatever that means), but I can't seem to find any real guidelines. What are some considerations you use when making this pr...

Maximum number of threads in a .NET app?

What is the maximum number of threads you can create in a C# application? And what happens when you reach this limit? Is an exception of some kind thrown? ...

What is the best way to produce random double on POSIX?

I'd like to get uniform distribution in range [0.0, 1.0) If possible, please let the implementation make use of random bytes from /dev/urandom. It would also be nice if your solution was thread-safe. If you're not sure, please indicate that. See some solution I thought about after reading other answers. ...

How to make a method exclusive in a multithreaded context ?

I have a method which should be executed in an exclusive fashion. Basically, it's a multi threaded application where the method is invoked periodically by a timer, but which could also be manually triggered by a user action. Let's take an example : The timer elapses, so the method is called. The task could take a few seconds. Right af...

Has anyone written a thread-safe BindingList<T>?

I am currently getting exceptions when modifying an IBindingList on multiple threads. Does anyone have a threadsafe version before I write my own? ...

C# play a sound wait for it to finish then do something?

Hey I'm writing a windows forms application which is supposed to play a three sound files and at the end of each sound file it's to change the source of an image. I can get it to play the sounds using System.Media.SoundPlayer. However it seems to play the sound in a different thread, continuing on. The net effect of this is that only t...

Patterns for Multithreaded Network Server in C#

Are there any templates/patterns/guides I can follow for designing a multithreaded server? I can't find anything terribly useful online through my google searches. My program will start a thread to listen for connections using TcpListener. Every client connection will be handled by it's own IClientHandler thread. The server will wrap ...

Winforms threading problem, second thread can't access 1st main forms controls

I have a winforms application, the issue has to do with threading. Since I am calling 'MyCustomCode() which creates a new thread, and calls the method 'SomeMethod()' which then accesses MessageBox.Show(...). The problem has to do with threading, since the newly created thread is trying to access a control that was created on another th...

Interlocked equivalent on Linux

In a C++ Linux app, what is the simplest way to get the functionality that the Interlocked functions on Win32 provide? Specifically, a lightweight way to atomically increment or add 32 or 64 bit integers? ...

Naming conventions for threads?

It's helpful to name threads so one can sort out which threads are doing what for diagnostic and debugging purposes. Is there a particular naming convention for threads in a heavily multi-threaded application that works better than another? Any guidelines? What kind of information should go into the name for a thread? What have you lear...

When ThreadPool.QueueUserWorkItem returns false

The MSDN states that the method returns true if the method is successfully queued; NotSupportedException is thrown if the work item is not queued. For testing purposes how to get the method to return false? Or it is just a "suboptimal" class design? ...

Asynchronous WPF Commands

Note: The code in this question is part of deSleeper if you want the full source. One of the things I wanted out of commands was a baked design for asynchronous operations. I wanted the button pressed to disable while the command was executing, and come back when complete. I wanted the actual work to be performed in a ThreadPool work ...

Which CPU architectures support Compare And Swap (CAS)?

Hi, just curious to know which CPU architectures support compare and swap atomic primitives? ...

High-level Compare And Swap (CAS) functions?

I'd like to document what high-level (i.e. C++ not inline assembler ) functions or macros are available for Compare And Swap (CAS) atomic primitives... E.g., WIN32 on x86 has a family of functions _InterlockedCompareExchange in the <_intrin.h> header. ...

In Java, do I need to declare my collection synchronized if it's read-only ?

I fill a collection one single time when my J2EE webapp starts. Then, several thread may access it at same time but only to read it. I know using a synchronized collection is mandatory for parallels write but do I still need it for parallels read ? ...