Function to lock a named resource
LOCKRESOURCE(<cResource> [, <cMode>])
The LOCKRESOURCE() function attempts to lock the named resource <cResource> in mode <cMode>.
|<cResource>||Character string specifying the name of the resource|
|<cMode>||Character string specifying the mode: "shared" or "exclusive"|
The LOCKRESOURCE() function is cluster aware and can safely be used across multiple running instances of either Lianja desktop Apps on a network or Lianja Cloud Server instances.
'Shared' locks provide the ability to have multiple readers whereas 'exclusive' locks only provide access to a named resource one process at a time. If the named resource is locked exclusive by another process then the requesting process will wait until the resource is available in a compatible lock mode.
The 'LianjaCloudServerRequestLoop' resource is a built-in resource used by the Lianja Cloud Server. When a request is made to the Lianja Cloud Server a 'shared' lock is placed on the 'LianjaCloudServerRequestLoop' resource and then released at the end of the request. An rsp script placing an 'exclusive' lock on 'LianjaCloudServerRequestLoop' can therefore temporarily block the processing of other Lianja Cloud Server requests, for example to carry out database upgrade operations. Once the required operations are complete, issuing UNLOCKRESOURCE(<cResource>) or UNLOCKRESOURCEALL() will release the lock.
The 'resourcelocks' sub-directory of lianja must exist and be writable (default). If required, an alternative directory can be specified by creating and setting the DB_RESOURCELOCKSDIR environment variable.
<%@ Language=VFP %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> </head> <body> <% unlockResource("LianjaCloudServerRequestLoop") lockResource("LianjaCloudServerRequestLoop", "exclusive") // Once the exclusive lock has been granted carry out required operations // ... // Then release the lock to unblock other requests unlockResource("LianjaCloudServerRequestLoop") %> </body> </html> // Custom named resource: lockResource("myresource", "exclusive") // Resources can be unlocked individually by name: unlockResource("myresource") // Or all previously locked resources can be unlocked: unlockresourceall()