multithreading

problem with closing sockets

Hi, I'm trying to write a client/server program with threads. I close the socket once the connexion is finished. The servers gets plenty of new connexions, and the socket number (file descriptor) increases very quickly: after 5 minutes running I was already at around file descriptor number 800! Is this a normal thing? Do threads share...

Catching Exceptions in a .NET Thread

How could you find out that an Exception occurred in a Thread in a MultiThreaded Application ? and consecutively clean the resources ? Because otherwise the Thread can be still remaining in memory and running. ...

creating custom event / signal on cocoa os x

I am not much familiar with developing application using cocoa on mac. Can some one help me with how can i create custom events or signals, and how to make sure thread acts when these are generated or triggered. Any help will be appreciated. ...

Debugging instance of another thread altering my data

I have a huge global array of structures. Some regions of the array are tied to individual threads and those threads can modify their regions of the array without having to use critical sections. But there is one special region of the array which all threads may have access to. The code that accesses these parts of the array needs to car...

What is a class level lock in java

What is a class level lock. Can you please explain with an example. ...

WinForms equivalent of performSelectorOnMainThread in Objective-C

I haven't done much multithreading before and now find the need to do some background work and keep the UI responsive. I have the following code. data.ImportProgressChanged += new DataAccess.ImportDelegate(data_ImportProgressChanged); Thread importThread = new Thread( new ThreadStart(data.ImportPeopleFromFAD)); importThre...

Using static mutex in a class

I have a class that I can have many instances of. Inside it creates and initializes some members from a 3rd party library (that use some global variables) and is not thread-safe. I thought about using static boost::mutex, that would be locked in my class constructor and destructor. Thus creating and destroying instances among my threads...

Java threads problem

Hi! I have a problem with java threads: public class MyClass{ public void Core(){ runTools(); //here I would like to call runTools() method } public void runTools(){ final String run_tool ="cmd.exe /C sources.exe"; Runnable doRun = new Runnable() { public void run() { try { Process tool_proc = Runtime.getRuntim...

Need events to execute on timer events, metronome precision.

I setup a timer to call an event in my application. The problme is the event execution is being skewed by other windows operations. Ex. openning and window, loading a webpage. I need the event to excute exactly on time, every time. When i first set up the app, used a sound file, like a metronome to listen to the even firing, in a stead...

Inner synchronization on the same object as the outer synchronization

Recently I attended a lecture concerning some design patterns: The following code had been displayed: public static Singleton getInstance() { if (instance == null) { synchronized(Singleton.class) { //1 Singleton inst = instance; //2 if (inst == null) { synchronized(Singleton.class) { //3 ...

synchronize threads - no UI

I'm trying to write multithreading code and facing some synchronization questions. I know there are lots of posts here but I couldn't find anything that fits. I have a System.Timers.Timer that elapsed every 30 seconds it goes to the db and checks if there are any new jobs. If he finds one, he executes the job on the current thread (time...

Threading errors with Application.LoadComponent (key already exists)

MSDN says that public static members of System.Windows.Application are thread safe. But when I try to run my app with multiple threads I get the following exception: ArgumentException: An entry with the same key already exists. at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) at System.Collections.Generic....

MS Exam 70-536 - How to throw and handle exception from thread?

Hello! In MS Exam 70-536 .Net Foundation, Chapter 7 "Threading" in Lesson 1 Creating Threads there is a text: Be aware that because the WorkWithParameter method takes an object, Thread.Start could be called with any object instead of the string it expects. Being careful in choosing your starting method for a thread to deal with...

Can CompareExchange be implemented with CompareAndSwap?

Assuming that CompareAndSwap (or CAS) never fails spuriously, can CompareExchange be implemented with CAS? CompareExchange both take a pointer, an expected value, and a new value and atomically set the memory referenced by the pointer to the new value if it matches the expected value. The difference between the two is that CompareExcha...

System.WIndows.Application static members are thread safe?

The Application static members are supposed to be thread safe: The public static (Shared in Visual Basic) members of this type are thread safe. In addition, the FindResource and TryFindResource methods and the Properties and Resources properties are thread safe.1 How much can we trust that statement in a multithreaded env...

WCF Service worker thread communicate with ServiceHost thread

I have a windows NT Service that opens a ServiceHost object. The service host context is per-session so for each client a new worker thread is created. What I am trying to do is have each worker thread make calls to the thread that started the service host. The NT Service needs to open a VPN connection and poll information from a devic...

C# Thread Pool Cross-Thread Communication

The Scenario I have a windows forms application containing a MAINFORM with a listbox on it. The MAINFORM also has a THREAD POOL that creates new threads and fires them off to do lots of different bits of processing. Whilst each of these different worker threads is doing its job, I want to report this progress back to my MAINFORM, howeve...

Parallel programming patterns for C#?

With Intel's launch of a Hexa-Core(6) processor for the desktop, it looks like we can no longer wait for Microsoft to make many-core programming "easy". I just order a copy of Joe Duffy's book Concurrent Programming on Windows. This looks like a great place to start, though, I am hoping some of you who have been targeting multi/many co...

Segmentation fault on MPI, runs properly on OpenMP

Hi, I am trying to run a program on a computer cluster. The structure of the program is the following: PROGRAM something ... CALL subroutine1(...) ... END PROGRAM SUBROUTINE subroutine1(...) ... DO i=1,n CALL subroutine2(...) ENDDO ... END SUBROUTINE SUBROUTINE subroutine2(...) ... CALL subroutine3(...) CALL subroutine4(...) ... END ...

Twisted: why is it that passing a deferred callback to a deferred thread makes the thread blocking all of a sudden?

I unsuccessfully tried using txredis (the non blocking twisted api for redis) for a persisting message queue I'm trying to set up with a scrapy project I am working on. I found that although the client was not blocking, it became much slower than it could have been because what should have been one event in the reactor loop was split up ...