critical-section

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...

Unit Testing Refcounted Critical Section Class

Hello all :) I'm looking at a simple class I have to manage critical sections and locks, and I'd like to cover this with test cases. Does this make sense, and how would one go about doing it? It's difficult because the only way to verify the class works is to setup very complicated threading scenarios, and even then there's not a good w...

How to protect critical section in PHP?

I did some search about this topic but found nothing valuable. If I don't use PHP default session handler, there is no session lock at request level. So, I have to protect critical section by myself. In Java, we have synchronized. In C#, we have lock. In PHP, how to do that? ...

How to use CriticalSection - MFC?

I' am working on a small example and am a bit of curious using criticalsection in my example. What I'am doing is,I have a CStringArray(which has 10 elements added to it).I want to copy these 10 elements(string) to another CStringArray(am doing this to understand threading and Critical section),I have created 2 threads,Thread1 will copy ...

Thread safety in C# arrays

Does having 2 different threads : one reading from a C# array (e.g from first location), and another one writing to the same C# array but to a different location(e.g to the last location) is thread safe or not? (And I mean here without locking reading nor writing) ...

Delphi 2009: How do I prevent network application from leaking critical section?

As part of Vista certification, Microsoft wants to make sure that an application exits without holding on to a lock (critical section): TEST CASE 31. Verify application does not break into a debugger with the specified AppVerifier checks (Req:3.2) As it turns out, network applications built using Delphi 2009 does break into the de...

How to use Multiple Variables for a lock Scope in C#

I have a situation where a block of code should be executed only if two locker objects are free. I was hoping there would be something like: lock(a,b) { // this scope is in critical region } However, there seems to be nothing like that. So does it mean the only way for doing this is: lock(a) { lock(b) { // this...

Protecting critical sections based on a condition in C#

Hello, I'm dealing with a courious scenario. I'm using EntityFramework to save (insert/update) into a SQL database in a multithreaded environment. The problem is i need to access database to see whether a register with a particular key has been already created in order to set a field value (executing) or it's new to set a different val...

Critical section initialization when creating thread-safe singleton (C++)

I'm trying to do the same thing as suggested in this solution: http://stackoverflow.com/questions/164496/how-can-i-create-a-thread-safe-singleton-pattern-in-windows/164640#164640 But, where should the critical section be initialized and uninitialized? ...

Critical section problem

proces P0: proces P1: while (true) while (true) { { flag[0] = true; flag[1] = true; while (flag[1]) while (flag[0]) { { flag[0] = false; ...

Why do the threads run serially in this console application?

hi, I'm creating an console application which needs to run several threads in order to accomplish a task. My problem is that threads are running one after another (thread1 start -> work -> end and ONLY then start thread2) instead of running all in the same time. Also i don't want more than 10 threads to work in the same time(performance...

how to code thread synchronization using any method - eg ..Cevent

hello there I am trying to code a simple application which would help me in reading from a serial port and write to the same serial port using a single thread ...so could someone please help me to manage the synchronization between the threads.heres the source code- the whole project file in Visual studio 6 - http://rapidshare.com/files/...

Are there any consequences to never deleting critical sections?

I am refining a large body of native code which uses a few static critical sections and never calls DeleteCriticalSection, leaving them to process exit to clean up. There are no leaks and no concerns about the total number of CS getting too high, I'm just wondering if there are any long-term Windows consequences to not cleaning them up....

Replace critical section with SRW lock

If the application is targeted on Windows Vista or later, could we replace all critical sections with SRW locks? Since critical section is mutually exclusive, for usage it is equivalent to SRW locks in exclusive mode, right? According to MSDN, SRW is optimized both for speed and space. Is there any drawback for doing this? I'm not sure h...

What's the functioning scope of an critical section locker in c++?

// locks a critical section, and unlocks it automatically // when the lock goes out of scope CAutoLock(CCritSec * plock) The above is from wxutil.h, does it lock the access of different process , or just locks different threads in the same process? ...

Data access synchronization between multiple threads.

Hi, I'm trying to implement a multi threaded, recursive file search logic in Visual C++. The logic is as follows: Threads 1,2 will start at a directory location and match the files present in the directory with the search criteria. If they find a child directory, they will add it to a work Queue. Once a thread finishes with the files in...

Can I nest critical sections? Is TCriticalSection nestable?

I want to have two procedures which can call each other, or be called from whatever threads are running, but only have one running at a time. How can I do this? Will this work correctly? var cs: TCriticalSection; procedure a; begin cs.Acquire; try // Execute single threaded here. finally cs.Release; end; end; proce...

COM - what does _pAtlModule->Lock() lock exactly?

Hi I'm working my way through learning writing a COM control. I've got an example project, and it uses the lines _pAtlModule->Lock() _pAtlModule->Unlock() in the OnCreate() handler and the OnDestroy() handler for the COM control respectively. I realise that the _pAtlModule is an instance of the CAtlModule - the "application" object ...

Delphi: Debug critical section hang by reporting call stack of running threads on lock "failure"

I'm looking for a way to debug a rare Delphi 7 critical section (TCriticalSection) hang/deadlock. In this case, if a thread is waiting on a critical section for more than say 10 seconds, I'd like to produce a report with the stack trace of both the thread currently locking the critical section and also the thread that failed to be able ...

Java, multiple threads with only one executing at a time

I am working on an assignment and have to create two classes, one represents a person, and the other representing a bridge. Only one person can be "crossing" the bridge at any one time, but there could be people waiting to cross I easily implemented this with multi-threading allowing for multiple people to cross at once, but I am having...