EnableCriticalSections, BeginCriticalSection, and EndCriticalSection Subroutine

Purpose

Enables a thread to be exempted from timeslicing and signal suspension, and protects critical sections.

Library

Standard C Library (libc.a)

Syntax

#include <sys/thread_ctl.h>

int EnableCriticalSections(void);
void BeginCriticalSection(void);
void EndCriticalSection(void);

Description

When called, the EnableCriticalSections subroutine enables the thread to be exempted from timeslicing and signal suspension. Once that is done, the thread can call the BeginCriticalSection and EndCriticalSection subroutines to protect critical sections. Calling the BeginCriticalSection and EndCriticalSection subroutines with exemption disabled has no effect. The subroutines are safe for use by multithreaded applications.

Once the service is enabled, the thread can protect critical sections by calling the BeginCriticalSection and EndCriticalSection subroutines. Calling the BeginCriticalSection subroutine will exempt the thread from timeslicing and suspension. Calling the EndCriticalSection subroutine will clear exemption for the thread.

The BeginCriticalSection subroutine will not make a system call. The EndCriticalSection subroutine might make a system call if the thread was granted a benefit during the critical section. The purpose of the system call would be to notify the kernel that any posted but undelivered stop signals can be delivered, and any postponed timeslice can now be completed.

Return Values

The EnableCriticalSections subroutine returns a zero.