Welcome to the Harris Geospatial product documentation center. Here you will find reference guides, help documents, and product libraries.


SEM_LOCK

SEM_LOCK

The SEM_LOCK function attempts to gain the lock on an existing semaphore for the current IDL process. (Note that the semaphore could have been created by any process; IDL can lock semaphores created by other applications.) Once the lock has been obtained by an IDL process, other processes (including other IDL processes) will not be able to gain the lock until the SEM_RELEASE process is called within the IDL process that owns the lock. Similarly, an IDL process will not be able to obtain a lock on an existing semaphore if that semaphore is already locked by another process.

Example

This example illustrates the way semaphores operate using two independent IDL sessions on the same machine.

  1. The user starts IDL session 1.
  2. The user creates a semaphore using the following command:

    status = SEM_CREATE('semaphore1')

    This creates a semaphore called “semaphore1”.

  3. The user sets a lock on the semaphore using the following command:

    status = SEM_LOCK('semaphore1')

    If the lock is obtained, status is set equal to 1.

  4. The user starts IDL session 2.
  5. In session 2, the user creates a reference to the same semaphore created in session 1:

    status = SEM_CREATE('semaphore1')
  6. In session 2, the user attempts to gain the lock on the semaphore with the following command:

    status = SEM_LOCK('semaphore1')

    Since the lock is owned by session 1, status is set equal to 0 (the lock was not obtained).

  7. In session 1, the lock on the semaphore is released using the following command:

    SEM_RELEASE, 'semaphore1'
  8. Once the lock has been released in session 1, the user once again attempts to gain the lock on the semaphore in session 2:

    status = SEM_LOCK('semaphore1')

    In this case, status is set equal to 1, indicating session 2 now has the lock

  9. In session 1, attempting to retrieve the lock will result in failure, since session 2 has the lock on the semaphore.
  10. In session 2, the user executes the following command:

    SEM_DELETE, 'semaphore1'

    This removes the reference to the semaphore in session 2, but does not destroy the actual semaphore in the operating system.

  11. In session 1, the user executes the following command:

    SEM_DELETE, 'semaphore1'

    This removes both the reference to the semaphore in session 1 and the actual semaphore in the operating system, because:

    • If the user is on a UNIX system, the semaphore itself is destroyed because it was created in session 1 and there are no other references it.
    • If the user is on a Windows system, the semaphore itself is destroyed because session 1 has the last reference to it.

Syntax


Result = SEM_LOCK(strName)

Return Value


The result is 1 (one) if the lock on the specified semaphore was successfully obtained, or 0 (zero) if the lock could not be obtained.

Arguments


strName

A scalar string containing the name associated with the semaphore. This is the name used when creating the semaphore with SEM_CREATE.

Note: Semaphore names must be 24 characters or less on Macintosh platforms.

Keywords


None

Version History


6.3

Introduced

See Also


SEM_CREATE, SEM_DELETE, SEM_RELEASE



© 2017 Exelis Visual Information Solutions, Inc. |  Legal
My Account    |    Buy    |    Contact Us