Questions tagged [critical-section]

Critical section refers to either a piece of code that will run concurrently in several threads accessing global data or resources (requiring synchronisation), or a user-level spinlock combined with a mutex object under the Windows operating system. A critical section in the latter sense is functionally identical to a mutex that it cannot shared with a different process and that it is several orders of magnitudes faster in the non-congested case.

529 questions
12
votes
2 answers

Critical section in MPI?

I have some code to print a 2D array to the standard output. The problem is that when I run it, every process writes to the output and the data overlaps, rendering it unusable. How can i build a critical section in MPI so that only one process at a…
alexsardan
  • 253
  • 1
  • 4
  • 7
12
votes
1 answer

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…
Reci
  • 4,099
  • 3
  • 37
  • 42
11
votes
2 answers

Avoiding Cache Consistency Issues in Delphi With a Critical Section?

I just read a MSDN article, "Synchronization and Multiprocessor Issues", that addresses memory cache consistency issues on multiprocessor machines. This was really eye opening to me, because I would not have thought there could be a race condition…
Troy
  • 1,237
  • 2
  • 13
  • 27
11
votes
6 answers

.crt section? What does this warning mean?

I've got this warning recently (VC++ 2010) warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators I'm assuming this is the Critical Section. It's been a while since my Operating Systems course, so I can't…
MGZero
  • 5,812
  • 5
  • 29
  • 46
11
votes
2 answers

Critical sections in ARM

I am experienced in implementing critical sections on the AVR family of processors, where all you do is disable interrupts (with a memory barrier of course), do the critical operation, and then reenable interrupts: void my_critical_function() { …
DarthRubik
  • 3,927
  • 1
  • 18
  • 54
11
votes
1 answer

Will Peterson's solution work correctly on modern CPU architectures?

I am studying operating systems from Operating System Concepts by Silberschatz, Galvin, and Gagne. On page 229, the book states this about Petersons Solution : Because of the way modern computer architectures perform basic machine language…
asheeshr
  • 4,088
  • 6
  • 31
  • 50
10
votes
2 answers

Is there a difference between Boost's scoped mutex and WinAPi's critical section?

In Windows environment, is Boost's scoped mutex using WinAPI's critical sections, or something else?
nhaa123
  • 9,570
  • 11
  • 42
  • 63
10
votes
2 answers

How do I make a critical section with Boost?

For my cross-platform application I have started to use Boost, but I can't understand how I can implement code to reproduce behavior of Win32's critical section or .Net's lock. I want to write a method Foo that can be called from different threads…
Vie
  • 823
  • 1
  • 10
  • 18
10
votes
3 answers

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…
Shamim Hafiz - MSFT
  • 21,454
  • 43
  • 116
  • 176
10
votes
5 answers

do integer reads need to be critical section protected?

I have come across C++03 some code that takes this form: struct Foo { int a; int b; CRITICAL_SECTION cs; } // DoFoo::Foo foo_; void DoFoo::Foolish() { if( foo_.a == 4 ) { PerformSomeTask(); …
PaulH
  • 7,759
  • 8
  • 66
  • 143
9
votes
4 answers

Unhandled exception / Access violation writing location in a Mutex example

I'm working through an example of protecting a global double using mutexes, however I get the error - Unhandled exception at 0x77b6308e in Lab7.exe: 0xC0000005: Access violation writing location 0x00000068. I assume this is related to…
Eilidh
  • 1,354
  • 5
  • 21
  • 43
9
votes
5 answers

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…
Anagoge
  • 933
  • 1
  • 14
  • 23
9
votes
3 answers

Disable Hardware & Software Interrupts

Is it possible to disable all interrupts with a ASM/C/C++ program to get full control about the processor? If yes -> how? If not -> how do "atomic" operation system calls work (for example entering a critical section)? Thanks for your help!
someone
9
votes
10 answers

Win32 Read/Write Lock Using Only Critical Sections

I have to implement a read/write lock in C++ using the Win32 api as part of a project at work. All of the existing solutions use kernel objects (semaphores and mutexes) that require a context switch during execution. This is far too slow for my…
Dan Lorenc
  • 5,376
  • 1
  • 23
  • 34
8
votes
1 answer

Is it Safe to use 'Unsafe' Thread Functions?

Please pardon my slightly humorous title. I use two different definitions of the word 'safe' in it (obviously). I am rather new to threading (well, I have used threading for many years, but only very simple forms of it). Now I am faced with the…
1
2
3
35 36