KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Utility method to set Preemptive attribute on a method
PRODUCT: 4D | VERSION: 16 | PLATFORM: Mac & Win
Published On: November 2, 2017

In v16, attributes for Prremptive(thread safe ability) are now disclosed in the method when using the METHOD GET ATTRIBUTES command. Here is a utility method UTIL_SET_ATTR_PREEMPTIVE to set the attribute during run time:

// ----------------------------------------------------------------------
// Name: UTIL_SET_ATTR_PREEMPTIVE
// Description: Method will set the Preemptive attribute of a method.
//
// Parameters:
// $1 (TEXT) - Method Name
// $2 (LONG INT) - Scope:
// 1 - Capable - "Can be run in preemptive processes"
// 2 - Incapable - "Cannot be run in preemptive processes"
// 0 - No preference
//
// Output:
// $0 (LONG INT) - Status of setting attribute
// 0 - Success
// 1 - Error: Insufficient parameters
// 2 - Error: Found no method name
// ----------------------------------------------------------------------
C_TEXT($1;$method_name;$preemptive_property)
C_LONGINT($2;$choice;$loc_method)
C_LONGINT($0)
C_OBJECT($attributes)
ARRAY TEXT(arrPaths;0)

If (Count parameters=2)
   
    $method_name:=$1
    $choice:=$2
   
    METHOD GET PATHS(Path project method;arrPaths) // Get paths for Project methods
    $loc_method:=Find in array(arrPaths;$method_name;1)
   
    If ($loc_method>0)
     METHOD GET ATTRIBUTES(arrPaths{$loc_method};$attributes) // Method Attributes
   
     Case of
      : ($choice=1)
       $preemptive_property:="capable"
      : ($choice=2)
       $preemptive_property:="incapable"
      Else
       $preemptive_property:="indifferent"
     End case
   
    OB SET($attributes;"preemptive";$preemptive_property)
    METHOD SET ATTRIBUTES(arrPaths{$loc_method};$attributes) // Method Attributes
    $0:=0
    Else
     $0:=2
    End if
   Else
    $0:=1
End If

Example #1 Method executed will be thread "Capable":
C_LONGINT($status)

$status:=UTIL_SET_ATTR_PREEMPTIVE("Method1";1)





Example #2 Method executed will be thread "Incapable":
C_LONGINT($status)

$status:=UTIL_SET_ATTR_PREEMPTIVE("Method1";2)




Example #3 Method executed will have "Indifferent":
C_LONGINT($status)

$status:=UTIL_SET_ATTR_PREEMPTIVE("Method1";0)





See Also: