Since 4D v11, the database server and SQL server both use preemptive multi-threading. Starting with 4D v13, the Web Server in Static mode also uses preemptive. Now with v15 R5, the 4D language can also be run in preemptive processes.
Your 4D compiled applications will now be able to take full advantage of multi-core computers so that their execution will be faster and they can support more connected users.
What is the difference between Cooperative and Preemptive mode?
Cooperative mode is scheduled by processes and can only use one core. Preemptive mode is scheduled by the OS and can use all available cores.
Here an example with two processes and two cores:
How do I to execute a method in preemptive processes?
By default, 4D will execute all project methods in cooperative mode. If you want to benefit from the preemptive mode feature, the first step consists in explicitly declaring all methods that you want to be started in preemptive mode.
To do so, there is a new “Execution mode” property in the method properties. You have 3 options:
- Can be run in preemptive mode
- Cannot be run in preemptive mode
- Indifferent
When you open your database with 4D v15 R5, all your methods will be set to Indifferent.
How do I to check that my code can be run in preemptive processes?
Just write your code then the compiler checks whether the method is compatible or incompatible.
To see an example, watch this video:
If you want to reproduce all the previous demonstrations yourself, we suggest that you download the following example database.
How do I know what commands can be run in preemptive processes?
The 4D commands that can be run in preemptive processes are indicated in the documentation by a new icon. This icon is found on the top right side.
In v15 R5, a first set of commands is available. We will add more commands in following R-release.
We suggest that you download the following HDI. We have updated the “Command name” command so that you can find out whether or not the command can be run in preemptive mode.
For more details, please take a look at the 4D v15 R5 Upgrade manual.