Schnittstelle CriticalSection

Alle bekannten Implementierungsklassen:
CriticalSection.LockedCriticalSection, CriticalSection.SynchronizedCriticalSection, CriticalSection.UnsynchronizedCriticalSection

public interface CriticalSection
A critical section is a block of code that must be executed by only one thread at a time. This interface provides methods to run code blocks or callables within such a critical section. Implementations of this interface are expected to provide the necessary synchronization mechanisms to ensure thread safety.

Example usage:

 CriticalSection criticalSection = ...; // Obtain an implementation
 criticalSection.run(() -> {
   // Code to be executed in the critical section
   });

 int result = criticalSection.supply(() -> {
   // Code that returns a value
   return 42;
 });

 boolean flag = criticalSection.supply(() -> {
   // Code that returns a boolean
   return true;
 });

 double value = criticalSection.supply(() -> {
   // Code that returns a double
   return 3.14;
 });

 long count = criticalSection.supply(() -> {
   // Code that returns a long
   return 100L;
 });
 
Seit:
3.29
Autor:
Eike Stepper