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

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.

Avatar
• Product Owner •Damien Fuzeau has joined the 4D Product team in February 2019. As a Product Owner, he is in charge of writing user stories, then translating them to functional specifications. His job also entails making sure that the feature implementations delivered are meeting the customer needs.Damien is graduated from the University of Nantes in software engineering. He spent more than 23 years in its former company, first as developer (discovering 4D in 1997), and later as engineering manager and software architect. This company is a 4D OEM partner and deployed 4D based business softwares for thousands users, on hundreds servers. So, Damien is used to 4D development and deployment in a multi-language context.