4D Blog

Home Product Coexistence of thread-safe and non-thread-safe commands

Coexistence of thread-safe and non-thread-safe commands

November 27, 2019

Product

Have you ever needed to use methods with both thread-safe and not thread-safe calls, with conditions that skip over commands that are not thread-safe? Currently the compiler prevents doing this and an error is thrown, however there’s a flag that lets you disable this check and this blog post shows you how. 


In a caller method, you may have already changed both parts of the code; one part for the preemptive mode and the other part for the cooperative mode. However in this case, the compiler considers that the entire method is not thread-safe, even if the cooperative part of the code isn’t executed in preemptive mode. The methods calling this one aren’t considered thread-safe either!

What now?

To help you with this transition from cooperative to preemptive, 4D now lets you disable the compiler’s thread-safety checking of commands in parts of the code. To do this, just place the //%T- compiler directive before non-thread-safe code and //%T+ after it.

Here’s a sample that’s considered thread-safe by the compiler:

PROCESS PROPERTIES(Current process;$name;$state;$time;$flags)
$isPreemptive:=($flags ?? 1)
If ($isPreemptive)
LOG EVENT(Into Windows log events;"Error xy occured")
Else
//%T-
DIALOG("myErrorDialog";New object("message";"Error xy occured"))
//%T+
End if

If you execute non thread-safe commands between the //%T- and //%T+ compiler directives in a preemptive process, 4D simply throws an error.

Discuss

Tags Preemptive, Scalability, Thread safe, v18

Latest related posts

  • February 3, 2026

    4D Write Pro – Adding a margin automatically when bullets are set using standard actions

  • January 22, 2026

    Transform Static Documents into Actionable Knowledge with AIKit

  • January 22, 2026

    Deploy Fluent UI effortlessly in your 4D applications

Avatar
Damien Fuzeau
- Product Owner - Damien Fuzeau joined the 4D Product team in February 2019. As a Product Owner, he is responsible for writing user stories and translating them into functional specifications. His role also involves ensuring that the delivered feature implementations meet customer needs. Damien holds a degree in Software Engineering from the University of Nantes. He spent over 23 years at his previous company, first as a developer (discovering 4D in 1997), and later as Engineering Manager and Software Architect. The company was an OEM partner of 4D and deployed enterprise software based on 4D for thousands of users across hundreds of servers. Damien is therefore well-versed in 4D development and deployment in multilingual environments.
  • Deutsch
  • Français
  • English
  • Português
  • Čeština
  • Español
  • Italiano
  • 日本語

Categories

Browse categories

  • AI
  • 4D View Pro
  • 4D Write Pro
  • 4D for Mobile
  • Email
  • Development Mode
  • 4D Language
  • ORDA
  • User Interface / GUI
  • Qodly Studio
  • Server
  • Maintenance
  • Deployment
  • 4D Tutorials
  • Generic
  • 4D Summit sessions and other online videos

Tags

4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R10 21 21 R2 Administration AI Artificial Intelligence Build application CI/CD Class Client/Server Code editor Collections Formula Listbox Logs Mail Microsoft 365 Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience vscode Web Word processor

Tags

4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R10 21 21 R2 Administration AI Artificial Intelligence Build application CI/CD Class Client/Server Code editor Collections Formula Listbox Logs Mail Microsoft 365 Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience vscode Web Word processor
Subscribe to 4D Newsletter

© 2026 4D SAS - All rights reserved
Terms & Conditions | Legal Notices | Data Policy | Cookie Policy | Contact us | Write for us


Subscribe to 4D Newsletter

* Your privacy is very important to us. Please click here to view our Policy

Contact us

Got a question, suggestion or just want to get in touch with the 4D bloggers? Drop us a line!

* Your privacy is very important to us. Please click here to view our Policy