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!
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)
LOG EVENT(Into Windows log events;"Error xy occured")
DIALOG("myErrorDialog";New object("message";"Error xy occured"))
If you execute non thread-safe commands between the //%T- and //%T+ compiler directives in a preemptive process, 4D simply throws an error.