Talk:Critical section

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

Untitled[edit]

Following on from the comment below, I personally find this explanation of a critical section very confusing. Some questions:

  • how does protecting A's and B's update code by a critical section ensure that B executes its update before A reads it? From my reading of the explanation it simply prevents simultaneous access to x
  • Does protecting a piece of code by critical section ensure that no other process can enter its critical section at the same time? If so, that needs to be stated clearly
  • Similarly, is a critical section intended to be atomic? is the process cannot be interrupted during its execution? If so this needs to be stated clearly too

Houseofwealth (talk) 21:57, 12 February 2019 (UTC)[reply]

A critical section is a piece of code. but it isn't critical because executing itself, it is critical because the code causes a effect, at example change data. Two different pieces of code are critical together, the CRITICAL_SECTION - mechanism in Windows doesn't protect the entering of this alone critical section code piece, it protects the entry in different critical sections which effects the same data. In this mind the CRITICAL_SECTION-mechanism in Windows is a simple semaphore and the problem is a mutex problem.

I would say, a critical section is a piece of code, it's right. But the reason for a critical section may be several:

  1. mutex, exclusively acces to data
  2. time-critical actions like hardware access (microsecond-impuls generated by software). A interruption of this critical section can extend the time of a hardware pulse in a unneeded manner.
  3. prevent a thread switch (from a thread in a lower priority at example) to finish a mutex access in a short time, if the mutex access may block a high priority thread. The low priority thread mustn't be interrupted by a middle priority thread in this critical section.

That are three several examples. I would think, the explanation of critical section may be corrected in this mind. --HartmutS 18:43, 26 April 2006 (UTC)[reply]

Another important aspect is partial mutual exclusion. For example, code protected by the read side of a reader-writer lock excludes writers, but not other readers. Seems like some modification is in order to account for this -- in its current form, the article only allows for exclusive locks. PaulMcKenney 15:00, 26 May 2006 (UTC)[reply]

Gurudutt 10:16, 10 September 2007 (UTC) It should be possible to use pthread_spin_lock() family of functions to get Critical Section in User Mode in Pthreads Library. The current example shows the use of Mutex Object (kernel level)?? Being a newcomer to threading and esp. Pthreads this is just my 2 cents worth.[reply]

Wiki Education Foundation-supported course assignment[edit]

This article is or was the subject of a Wiki Education Foundation-supported course assignment. Further details are available on the course page. Student editor(s): Kartikharia, Akhande5.

Above undated message substituted from Template:Dashboard.wikiedu.org assignment by PrimeBOT (talk) 18:41, 16 January 2022 (UTC)[reply]

Introduction[edit]

The introduction to this article seems a bit long. It looks to me like only the first or the two first paragraphs needs to be in the introduction, the rest could be moved to a section of its own, called "Using critical sections" or something like that.

I'd go ahead and do it myself, but honestly I'm not sure I understand all the technical terms and I'm not really comfortable editing articles on subjects I don't fully comprehend. MMad (talk) 18:37, 15 November 2008 (UTC)[reply]

Windows NT family/ Critical Section vs Win32 Mutex[edit]

"Note that the use of a CriticalSection is not the same as a Win32 Mutex, which is an object used for inter-process synchronization"

I would phrase this differently, personally. Saying "not the same" implies to me a "not fit to do the same thing"/ "not similar". Both ( can ) ensure that a section of code is executed without allowing another thread to re-execute that code or protect data. A critical section is "lighter weight" than a mutex, I am told. A Mutex is a Kernel object, so access will enter the kernel. A Mutex can be used anywhere a critical section can be used. ( unnamed/named for local application, named for inter-process ) The reverse is not true.

David 66.193.194.18 (talk) 19:48, 21 April 2015 (UTC)[reply]

Critical sections[edit]

"A critical section object provides synchronization similar to that provided by a mutex object, except that a critical section can be used only by the threads of a single process. Event, mutex, and semaphore objects can also be used in a single-process application, but critical section objects provide a slightly faster, more efficient mechanism for mutual-exclusion synchronization (a processor-specific test and set instruction)."

> https://msdn.microsoft.com/en-us/library/windows/desktop/ms682530(v=vs.85).aspx

CS are only for threads of the owning process; the whole topic "Need for critical sections" is wrong because you cant share the handle of a CS. — Preceding unsigned comment added by 79.224.245.57 (talk) 14:31, 26 May 2017 (UTC)[reply]


The above isn't true since the definition in the linked msdn article talks about a CriticalSection object in .Net, not critical section in general