Locking An Interface - HP 9000 Series 300 Tutorials Manual

Device i/o and user interfacing hp-ux concepts and tutorials
Hide thumbs Also See for HP 9000 Series 300:
Table of Contents

Advertisement

Locking an Interface
Using a single interface to control multiple peripheral devices provides many
advantages in convenience, cost and system operating characteristics. However,
when several programs and/or several users need simultaneous access to
peripherals sharing a single interface, conflicts arise. This problem is especially
annoying when one user needs exclusive control of the interface during a set of
critical I/O operations. Unless a mechanism is provided to lock out other users
during critical program steps, useful results may be unobtainable in some cases.
Two DIL subroutines, io_lock and io_unlock are provided for this purpose.
The first locks the interface so that only the process that locked it can use
the interface until it is unlocked. The second unlocks the interface so other
processes can again access it.
When another process attempts to access a locked interface, the process will
sleep until the interface is unlocked (or a timeout occurs) if the O_NDELAY
flag was not set at the time the requesting process executed the open(2)
system call. If the O_NDELAY flag was set during the call to open(2) and the
interface is locked, any attempts to access the locked interface fail and the DIL
subroutine call from the process returns with an error.
Locks on an interface are owned by the process, and are not associated with
the eid. This means that the same process can access a given interface through
another eid if another open is performed on the device. If a process uses a
fork (2) system call to create a child process that uses the same interface, the
child does not inherit the current lock from the parent. Since it has a different
process ID than the parent, it also cannot access the locked interface file until
the parent unlocks it.
For good programming practice, any locks created by a process should be
unlocked through a call to
i~_unlock
before terminating. However, any locks
held by a process are released when the process terminates, whether or not a
call to io_unlock was executed. Refer to iO_lock(3I) in the HP- UX Reference
for more information about locking and unlocking interfaces.
Caution
Do not place a lock on any interface that supports any system
disc or swap device. Interface locks are enforced by the system,
and such a condition may require rebooting in order to recover.
2-14
General-Purpose Routines

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Hp 9000 series 800

Table of Contents