PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
This content has been translated automatically. Click here to view the French version.
  • Overview
  • What is a critical section
  • The CriticalSection variable
  • Critical section associated with a variable
  • Special case
  • Example
  • Remarks
  • Named critical section
  • How it works
  • Programming in WLanguage
  • Functions for managing critical sections
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Overview
semaphores s allow to limit the simultaneous execution of a code (procedure, code row, ...) to one or more threads at a given time. A semaphore can be shared between several applications.
Other systems can also be used to protect a code section:
  • Versions 16 and later
    Mutexes are used to limit the simultaneous execution of a code (procedure, line of code, etc.) to one thread at a given time. A mutex can be shared between several applications. For more details, see Managing mutexes in threads.
    New in version 16
    Mutexes are used to limit the simultaneous execution of a code (procedure, line of code, etc.) to one thread at a given time. A mutex can be shared between several applications. For more details, see Managing mutexes in threads.
    Mutexes are used to limit the simultaneous execution of a code (procedure, line of code, etc.) to one thread at a given time. A mutex can be shared between several applications. For more details, see Managing mutexes in threads.
  • Critical sections: A critical section is a semaphore limited to a single thread on a single code section (process, procedure, etc.).
What is a critical section
A critical section is a semaphore limited to a single thread on a single code section (process, procedure, etc.).
Unlike the semaphores, a critical section can be used once only.
For example, a critical section can be used to protect a procedure for updating the window controls.
Remark: The critical sections are unique for the application that created them. They cannot be shared between several applications.
WINDEV, WEBDEV and WINDEV Mobile offer several methods to implement critical sections.
Versions 24 and later
The CriticalSection variable
The CriticalSection variable allows to easily implement a critical section thanks to the syntax USING .. IN.
Example:
s is CriticalSection
UTILISER s IN
// code protégé par la section critique
// un seul thread pourra exécuter ce code à un moment donné
 
END
Remarks:
  • The CriticalSection type is used to simplify the declaration of critical sections.
  • CriticalSection variables respect the rules for variable scope.
AndroidAndroid Widget Not available in Android and in Android Widget.
New in version 24
The CriticalSection variable
The CriticalSection variable allows to easily implement a critical section thanks to the syntax USING .. IN.
Example:
s is CriticalSection
UTILISER s IN
// code protégé par la section critique
// un seul thread pourra exécuter ce code à un moment donné
 
END
Remarks:
  • The CriticalSection type is used to simplify the declaration of critical sections.
  • CriticalSection variables respect the rules for variable scope.
AndroidAndroid Widget Not available in Android and in Android Widget.
The CriticalSection variable
The CriticalSection variable allows to easily implement a critical section thanks to the syntax USING .. IN.
Example:
s is CriticalSection
UTILISER s IN
// code protégé par la section critique
// un seul thread pourra exécuter ce code à un moment donné
 
END
Remarks:
  • The CriticalSection type is used to simplify the declaration of critical sections.
  • CriticalSection variables respect the rules for variable scope.
AndroidAndroid Widget Not available in Android and in Android Widget.
Versions 21 and later
Critical section associated with a variable
When declaring a variable, this variable can be associated with a critical section by using the critical section attribute.
The syntax is as follows:
NomVariable est un TypeVariable <section critique>

ou

NomVariable est un TypeVariable, section critique
The code sections that use these variables must be found between CriticalSectionStart and CriticalSectionEnd.

Special case

A critical section is automatically associated with the variables on which simple operations are performed, such as:
  • assigning a value.
  • retrieving a value.
  • incrementat, decrement (+, -, ++, --, +=, -= operators +, -, ++, --, += -=).

Example

// Déclarations globales de la fenêtre FEN_STAT
gmoSomme is currency, critical section
gmoMax is currency, critical section
...
// Code exécuté par plusieurs threads
moMontantCommande is currency
...
// opération atomique, la section critique est gérée automatiquement par le WLangage
gmoSomme += moMontantCommande
 
// opération multiple, il est nécessaire de mettre en place la section critique explicitement
CriticalSectionStart(gmoMax)
IF moMontantCommande > gmoMax THEN
gmoMax = moMontantCommande
END
CriticalSectionEnd(gmoMax)
// Déclarations globales de la fenêtre FEN_STAT
gmoSomme is currency, critical section
gmoMax is currency, critical section
...
// Code exécuté par plusieurs threads
moMontantCommande is currency
...
// opération atomique, la section critique est gérée automatiquement par le WLangage
gmoSomme += moMontantCommande
 
// opération multiple, il est nécessaire de mettre en place la section critique explicitement
UTILISER CriticalSection(gmoMax) IN
IF moMontantCommande > gmoMax THEN
gmoMax = moMontantCommande
END
END

Remarks

  • The critical section attribute is allowed for:
    • the global project variables, set of procedures, window, page and report.
    • the local variables.
    • the members of classes.
    • the arrays: in this case, the attribute is associated with the array and not with the array elements.
  • The queues and the stacks are protected by default: the critical section attribute is not required.
AndroidAndroid Widget Not available in Android and in Android Widget.
New in version 21
Critical section associated with a variable
When declaring a variable, this variable can be associated with a critical section by using the critical section attribute.
The syntax is as follows:
NomVariable est un TypeVariable <section critique>

ou

NomVariable est un TypeVariable, section critique
The code sections that use these variables must be found between CriticalSectionStart and CriticalSectionEnd.

Special case

A critical section is automatically associated with the variables on which simple operations are performed, such as:
  • assigning a value.
  • retrieving a value.
  • incrementat, decrement (+, -, ++, --, +=, -= operators +, -, ++, --, += -=).

Example

// Déclarations globales de la fenêtre FEN_STAT
gmoSomme is currency, critical section
gmoMax is currency, critical section
...
// Code exécuté par plusieurs threads
moMontantCommande is currency
...
// opération atomique, la section critique est gérée automatiquement par le WLangage
gmoSomme += moMontantCommande
 
// opération multiple, il est nécessaire de mettre en place la section critique explicitement
CriticalSectionStart(gmoMax)
IF moMontantCommande > gmoMax THEN
gmoMax = moMontantCommande
END
CriticalSectionEnd(gmoMax)
// Déclarations globales de la fenêtre FEN_STAT
gmoSomme is currency, critical section
gmoMax is currency, critical section
...
// Code exécuté par plusieurs threads
moMontantCommande is currency
...
// opération atomique, la section critique est gérée automatiquement par le WLangage
gmoSomme += moMontantCommande
 
// opération multiple, il est nécessaire de mettre en place la section critique explicitement
UTILISER CriticalSection(gmoMax) IN
IF moMontantCommande > gmoMax THEN
gmoMax = moMontantCommande
END
END

Remarks

  • The critical section attribute is allowed for:
    • the global project variables, set of procedures, window, page and report.
    • the local variables.
    • the members of classes.
    • the arrays: in this case, the attribute is associated with the array and not with the array elements.
  • The queues and the stacks are protected by default: the critical section attribute is not required.
AndroidAndroid Widget Not available in Android and in Android Widget.
Critical section associated with a variable
When declaring a variable, this variable can be associated with a critical section by using the critical section attribute.
The syntax is as follows:
NomVariable est un TypeVariable <section critique>

ou

NomVariable est un TypeVariable, section critique
The code sections that use these variables must be found between CriticalSectionStart and CriticalSectionEnd.

Special case

A critical section is automatically associated with the variables on which simple operations are performed, such as:
  • assigning a value.
  • retrieving a value.
  • incrementat, decrement (+, -, ++, --, +=, -= operators +, -, ++, --, += -=).

Example

// Déclarations globales de la fenêtre FEN_STAT
gmoSomme is currency, critical section
gmoMax is currency, critical section
...
// Code exécuté par plusieurs threads
moMontantCommande is currency
...
// opération atomique, la section critique est gérée automatiquement par le WLangage
gmoSomme += moMontantCommande
 
// opération multiple, il est nécessaire de mettre en place la section critique explicitement
CriticalSectionStart(gmoMax)
IF moMontantCommande > gmoMax THEN
gmoMax = moMontantCommande
END
CriticalSectionEnd(gmoMax)
// Déclarations globales de la fenêtre FEN_STAT
gmoSomme is currency, critical section
gmoMax is currency, critical section
...
// Code exécuté par plusieurs threads
moMontantCommande is currency
...
// opération atomique, la section critique est gérée automatiquement par le WLangage
gmoSomme += moMontantCommande
 
// opération multiple, il est nécessaire de mettre en place la section critique explicitement
UTILISER CriticalSection(gmoMax) IN
IF moMontantCommande > gmoMax THEN
gmoMax = moMontantCommande
END
END

Remarks

  • The critical section attribute is allowed for:
    • the global project variables, set of procedures, window, page and report.
    • the local variables.
    • the members of classes.
    • the arrays: in this case, the attribute is associated with the array and not with the array elements.
  • The queues and the stacks are protected by default: the critical section attribute is not required.
AndroidAndroid Widget Not available in Android and in Android Widget.
Named critical section

How it works

The critical section is defined by CriticalSectionStart and ended by CriticalSectionEnd.
The name of the CriticalSection is passed as a parameter to these functions via a string.
Example:
// Utilisation d'une section critique nommée
CriticalSectionStart("MaSection")
// Deux threads ne pourront pas exécuter ce code en même temps
...
CriticalSectionEnd("MaSection")
This method of using critical sections has several drawbacks:
  • risk of collisions between several critical sections with the same name.
  • never-released critical sections.
AndroidAndroid Widget In Android, only the syntax with a named critical section is available.
Programming in WLanguage

Functions for managing critical sections

The following WLanguage functions are used to manage critical sections:
Versions 23 and later
CriticalSection
New in version 23
CriticalSection
CriticalSection
Enables a name or on-variable critical section in the statement USING ... IN.
Versions 09 and later
CriticalSectionEnd
New in version 09
CriticalSectionEnd
CriticalSectionEnd
Marks the end of critical section: the code will be run by another thread.
Versions 09 and later
CriticalSectionStart
New in version 09
CriticalSectionStart
CriticalSectionStart
Marks the start of a critical section: no other thread will be able to run the code as long as the current thread does not exit from the critical section.
Versions 24 and later
To manage critical sections, it is also possible to use the following type:
Versions 24 and later
CriticalSection
New in version 24
CriticalSection
CriticalSection
CriticalSection variables are used to define critical sections to limit the simultaneous execution of a code (procedure, line of code, etc.) to one thread at a given moment in an application.
AndroidAndroid Widget This type of variable is not available.
New in version 24
To manage critical sections, it is also possible to use the following type:
Versions 24 and later
CriticalSection
New in version 24
CriticalSection
CriticalSection
CriticalSection variables are used to define critical sections to limit the simultaneous execution of a code (procedure, line of code, etc.) to one thread at a given moment in an application.
AndroidAndroid Widget This type of variable is not available.
To manage critical sections, it is also possible to use the following type:
Versions 24 and later
CriticalSection
New in version 24
CriticalSection
CriticalSection
CriticalSection variables are used to define critical sections to limit the simultaneous execution of a code (procedure, line of code, etc.) to one thread at a given moment in an application.
AndroidAndroid Widget This type of variable is not available.
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment