Attempt to gain an advisory lock on the file |
Declaration: |
native function flock(number shared, number wait) |
Description: |
This function attempts to obtain an advisory lock on the associated file using the flock() mechanism. Note that it is only useful if all mechanisms accessing the file also use the same locking mechanism as the OS itself will not enforce the lock. If shared is true, a shared lock will be attempted instead of the default exclusive type. A shared lock is one that multiple processes can share at the same time, but will still cause an attempted exclusive lock to fail. An exclusive lock is one that only one process can posess at a time. If wait is true and the lock is held by another process, the function will wait for the lock to become free and then take it straight away, rather than returning immediately. If an error occurs, it will return -1 and err.str will be set. If the lock attempt is successful, it will return 0. If wait is false and the lock is held by another process, it will return 1. To remove a lock, either call unlock() or close the file. Locks are automatically destroyed if the program exits. Note: this function is not available on all operating systems. |
Parameters: |
Parameter #1: number shared - If true, get a shared lock instead of exclusive |
Parameter #2: number wait - If true, wait for the lock instead of failing |
Returns: |
-1 on error, 0 on success, 1 if already locked |