multithreading

Does GetSystemInfo give you the total number of virtual CPUs (i.e. hyper-threaded)?

GetSystemInfo will give you the number of physical CPUs / cores, but I would like to know the total number of virtual CPUs. I.e. on the new Nahelam chips, they have 4 cores, but appear as 8 cpus. If GetSystemInfo doesn't give this information, what API do I need (I've seen a function for getting number of logical processors, but it is V...

C# Question about thread safety

I'm using a threadpool to do some heavy processing and also bits of sql. Currently I open sql connections when I need them, run a query and then close them. This works fine. The application has been running with no issues. As more work is being done by this application it's using more threads. More threads mean more opening/closing of SQ...

Static fields in an ASP.NET Webservice

Is a static variable in a webservice shared between all running invocations of the webservice on a server? In my case I want a server-wide sync-lock, and I beleive I can accomplish that with a single private static Object syncHandle = new Object(); Is that correct? ...

C# Multithreading issue with Monitor-class - possible lifelock?

I have a bit of code, which I can't figure out properly. The problem is that the program is multithreaded and within there is a bit of code that should be synchronized so I wrote this: lock (lockObject) { if (!Monitor.TryEnter(lockObject)) Monitor.Wait(lockObject); //do stuff... Monitor.PulseAll(lockObject); } Monitor.Exi...

Concurrency implications of EAFP/LBYL

When writing concurrent/multithreaded code in Python, is it especially important to follow the "Easier to Ask for Forgiveness than Permission" (EAFP) idiom, rather than "Look Before You Leap" (LBYL)? Python's exceptionally dynamic nature means that almost anything (e.g., attribute removal) can happen between looking and leaping---if so,...

Serial port communication: polling serial port vs using serial port DataReceived event

I am just reviewing some code I wrote to communicate with the serial port in C# on CF2.0. I am not using DataReceived event since it's not reliable. MSDN states that: The DataReceived event is not gauranteed to be raised for every byte received. Use the BytesToRead property to determine how much data is left to be read in the...

CreateProcess suspended cant resume

the code: bool success=CreateProcess(m_Process, NULL, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS||CREATE_SUSPENDED, NULL, NULL, &suInfo, &procInfo); if(!success){ MessageBoxA(0,"Could not create process...","ERROR",MB...

Should destructors be threadsafe?

I was going through a legacy code and found the following snippet: MyClass::~MyClass() { EnterCriticalSection(&cs); //Access Data Members, **NO Global** members are being accessed here LeaveCriticalSection(&cs); } I am wondering will it help by any chance to guard the destructor ? Consider a scenario : 1. Thread1 - About to...

Is using a Mutex to prevent multipule instances of the same program from running safe?

I'm using this code to prevent a second instance of my program from running at the same time, is it safe? Mutex appSingleton = new System.Threading.Mutex(false, "WinSyncSingalInstanceMutx"); if (appSingleton.WaitOne(0, false)) { Application.EnableVisualStyles(); Application.SetCompatibleTextRender...

How can I implement an algorithm for multicore in Java?

Modern computers have more and more cores. We want to change our current linear algorithm to use these cores. A splitting of any algorithm to use different threads only makes sense if there is a free processor. Are there any good libraries that can help to parallelize some steps if there are free processors? I will give some examples....

Is it possible to wait for methods that aren't in Threads to finish in Java?

I have an object which does some computation, then for each iteraction I want to draw what happens. While the drawing is happening, I want it to wait. This is what I did, basically: synchronized public void compute() { other.mark(variable); try { wait(); } catch(InterruptedException e) { } } in the...

Ruby/Rails thread safety

I have been hacking with Ruby from time to time, but I haven't done anything big or multithreaded with it. I have heard that MRI only supports green threads and JRuby supports native threads via JVM. However, I stumble upon comments on blogs and discussion groups which say that "Rails is not thread-safe" or that Ruby itself is not thread...

Delphi - How to Listen and Handle WMDeviceChange Messages while a task is executing?

I ran into the problem that two drives connected at nearly the same time can't be processed. I've actually fixed the old scsi way of getting the drive model but I have a feeling I'm about to run into this same problem. It appears that if a task is executing, such as the one I have checking if the drive is a particular device and unfort...

How to block Winforms UI while background thread is running

I've inherited a Winforms application that does a lot of long running calls into the application server from the UI thread, so the UI stays unresponsive, unusable, unclosable for quite some time. (Which makes me really go AAAAAAAAARGH!) I plan to move the server calls to a background thread and have the UI disabled - but movable & closa...

Linked List Thread safe?

Well i writing in .net and i have a list to witch i will only add item never remove and its a linked list i can change that if its not the best pick but any way to the point would it be safe to not use any locking in this case when i know that this list will never be changed in any other manner but that its added to? (a lock will be used...

How do you repeatedly call a Thread in Java?

I want a thread to execute in the background every 500 milliseconds. To do that, I extended a Thread, implemented ActionListener and put the class that I extended into a Timer. The Timer calls run() every 500 milliseconds. However, my whole Swing GUI freezes up when this thread is downloading stuff from the Internet. I want it to run in ...

Rendering to a single Bitmap object from multiple threads

What im doing is rendering a number of bitmaps to a single bitmap. There could be hundreds of images and the bitmap being rendered to could be over 1000x1000 pixels. Im hoping to speed up this process by using multiple threads but since the Bitmap object is not thread-safe it cant be rendered to directly concurrently. What im thinking i...

Synchronising an Asynchronous call in c#

I've run into quite an awkward predicament in a project at work. We need to create users across 4 or 5 different services, and have set it up in such a way that if one fails, they all fail. They're encapsulated within a transaction scope block. One of the services we need to add users to requires telnetting in, and fudging some data. Th...

Best practice for detecting when group of threads are done

What's the best practice for detecting when a whole group of threads are done processing? I have a process that will query a [long running] web service for an arbitrary number of objects, and then needs to take a transactional action when all of them have completed successfully. I am currently running them asynchronously, using delegat...

Running a non-thread-safe dll in a multithreading windows http server

I need to encapsulate a VB6 application as a COM object that will be called by IIS. One of the dlls used by the VB6 app is NOT thread-safe. How can I make sure that whenever my COM object is called it doesn't share the same dll with other instances of itself? I read somewhere that ActiveX exes run each instance in a different process,...