multithreading

confirming program flow

can someone tell if the code below would work fine? class CriticalSection{ int iProcessId, iCounter=0; public static boolean[] freq = new boolean[Global.iParameter[2]]; int busy; //constructors CriticalSection(){} CriticalSection(int iPid){ this.iProcessId = iPid; } int freqAvailable(){ for(int i=0; i< Global.iParameter[2]; ...

Reading log from Log4Net generated by multiple threads

I have a script that has multiple threads running in parallel. These threads write to a Log4Net RollingFileAppender file. Reading this log is a quite confusing since all the thread logs are mixed up. Im wondering what is a good way to write these logs, and what is the best way to read these files so reading the debugging information of a...

What is more advisable to create a thread by extending a Thread class or implementing Runnable?

Hi I like to know which is more preferable to create a thread by extending thread class or by implementing Runnable interface.And Why ? Thanks.. ...

Unit test System.Threading.Timer in .NET

How to unit test a timer based on System.Threading.Timer in .NET The System.Threading.Timer has a callback method ...

Scintilla and thread safety

I'm using the Scintilla edit control on Windows (Win32, C/C++) . The control is created in WndProc. I have a second thread, created with Boost.Thread, that act as a spell checker and marks with red squiggle incorrectly spelled words. Therefore, I have two threads altering the content of the Scintilla control. At first, the program was ...

C#: Automating the InvokeRequired code pattern

I have become painfully aware of just how often one needs to write the following code pattern in event-driven GUI code, where private void DoGUISwitch() { // cruisin for a bruisin' through exception city object1.Visible = true; object2.Visible = false; } becomes private void DoGUISwitch() { if (object1.InvokeRequir...

When does this happen? Thread suspended while in critical section

I'm just wondering, if a thread is in a critical section, can it be preempted? Thread A: Enter CR Thread A: Get suspended Thread B: Wants to enter CR but can't, because Thread A has the lock If Thread A preempted, and so the mutex lock is stuck with Thread A, what can be done about this? ...

Multithreaded application concept

Hi to all, i'm developing a multi-threaded application and i'm here to ask for a little help :) As i don't have much experience in multi-threading, especially in win32 API and this is my very first experience with it, i just wanted to check if I'm on the right way with my abstract model. I have read a reasonable amount of literature be...

Multi-core processor pegged even when all threads are just sleeping

I'm simulating some threading in a Windows Service, and the Thread.Start routine for each of my threads points directly to the following: Private WithEvents CheckForOrdersTimer As System.Threading.Timer Private Sub timerCheckForContracts_Tick(ByVal stateInfo As Object) ' Ticks every 5 seconds, then spawns threads until we're at our...

How is thread synchronization implemented, at the assembly language level?

While I'm familiar with concurrent programming concepts such as mutexes and semaphores, I have never understood how they are implemented at the assembly language level. I imagine there being a set of memory "flags" saying: lock A is held by thread 1 lock B is held by thread 3 lock C is not held by any thread etc But how is access to...

Sorting a vector using threads

Hi, Are the vectors defined in the C++ STL re-entrant or thread safe? Can I use two threads and work(in this case sort) on two halfs of a vector without using a mutex? For example: int size = (Data_List.size())/2; Thread A() { ................ // Do we need to lock Data_list with a mutex sort(Data_List.begin(),Data_List.begin()+size...

How to Lock Queue Variable Address instead of using Critical Section ?

Hi, I have 2 threads and global Queue, one thread (t1) push the data and another one(t2) pops the data, i wanted to sync this operation without using function where we can use that queue with critical section using windows API. The Queue is global, and i wanted to know how to sync, is it done by locking address of Queue?. Answers wil...

An unhandled win32 exception occurred in MyApp.exe

WinXP used. When I click the default cross icon to close my application. The win form of my application disappeared, but MyApp process still alive in the processes list when I open the task manager window. About 5 seconds later, throw out the unhandled win32 exception error. Where can I set the break point? I don't know how to debug it...

synchronous Vs asynchronous ruminations

Hey, Lets say I have my netwrok thread , which inside it I get Data regarding some people,and each record(of 1 man) is being put inside a queue. I have another Calcthread who reads from that queue and performs some calculation and DB actions. Since the calculation and DB actions take quite amount of time, I though doing the calculation...

Threading practices. Modelling application

Hi, all. There is the situation - i made some math modelling app on C#(WPF), showing it's results in realtime vector graphics. Math is doing fine (iterative process, per frame drawing), but there is the problem - while i'm using additional thread to do calculations, to draw result is should use Dispatcher.BeginInvoke (each frame!) which ...

Can a ThreadAbortException be raised during Thread.Sleep ?

Can Thread.Abort interrupt a thread that is sleeping (using, say, Thread.Sleep(TimeSpan.FromDays(40)) ? Or will it wait until the sleep time span has expired ? (Remarks: FromDays(40) is of course a joke. And I know Thread.Abort is not a recommended way to stop a thread, I'm working with legacy code that I don't want to refactor for now....

C# Convoyor-Belt-like buffer - Time constrained buffer

Hello, I'd like to program a buffer that is time constrained. It means that I want to be able to continuously fill up a List of string (for instance) and every 2 secondes that list is added to another list (or send to the network) whether this list has 1 or more elements, but another List of string take its place so that there are alway...

C# DataSource Class and Thread Safety

What would be a good way to writein C# a .NET3.5 Thread Safe DataSource Class. The class would connect to SQL Server and every method would execute a Stored Procedure. When the code worked single threaded. I had a Singleton DataSource Class with a private SqlConnection member. Each method opened and closed that connection. When running...

C# background thread causes lag in UI

I'm working on a realtime imaging system. UI thread: grabs images from a camera at 14 fps via timer and does some processing/display. Every 2 seconds, 3 images (about 1mb on disk each) are selected by processing to be written to disk. These are put in a shared queue. Second thread: dequeues images and writes to disk. Has been given 'Lo...

Multi threaded(Reentrant) MFC DLL

I need to load the same dll and use its functionalities in "n" number of threads in the same process. Will there be any problem in doing so or is there a better way to handle the above scenario? ...