I realized that I wanted to know for some error logs if the current process
is preemptive (thread-safe) or not. So I checked PROCESS PROPERTIES and,
yes, it will tell you. But it uses bit math. Oh no! I always run away from
bit math...and I decided that I was being silly to do so today. The "math"
in this case is nothing but an operator, not even slightly hard. So, here's
the code which I've tested out and seems to work:

// Process_IsPreemptive
// DESCRIPTION: Tests is process is running preemptively.

C_BOOLEAN($0;$is_preemptive)
C_LONGINT($1;$process_id)

If (Count parameters>=1)
$process_id:=$1
Else
$process_id:=Current process
End if

C_TEXT($name)
C_LONGINT($state;$time;$mode)
PROCESS PROPERTIES(Current process;$name;$state;$time;$mode)

C_BOOLEAN($preemptive)
$is_preemptive:=$mode ?? 1

$0:=$is_preemptive

This is handy for error logs, as mentioned, and also just to verify what's
going on. It's surprisingly tricky to launch a process in preemptive
mode...or least I find it so. You can use New process, Execute on server or
CALL WORKER, or so the docs say. I tried this code out with a worker and a
standard process, both in single-user. (Preemptive mode isn't supported on
4D Remote because....we don't know, 4D hasn't said. Presumably something in
the network layer?)

Tip: The order of arguments for method to run and process name are the same
for New process and Execute on server but are reversed on CALL WORKER.

Tip: The easy way to see the state of a process is from the Runtime
Explorer. There are new icons since late in the V15R series for each sort
of process. Oddly enough, a preemptive process' icon changes to a
cooperative process icon when it dies. So, don't necessarily trust the
icons for dead processes.
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**********************************************************************

Reply via email to