The IPrivateResource class defines a resource that is used within a single process.
IResource and its inherited classes represent resources in the user's problem domain. Objects of these classes name a particular resource. For example, a user wants to serialize access to the data in a window list collection. The user creates an IResource inherited class to represent the window list and then uses IResourceLock (preferred) or a function of IResource itself to lock and unlock the resource to serialize the access. You can use this class either alone (lock and unlock) or in combination with an IResourceLock, whose constructor locks the resource and whose destructor unlocks the resource. If you need the lock only for a block of code, use IResourceLock. Use static objects because you only need a single object of a particular IResource.
The static object pointer discussions exist because there is no language-defined way to ensure that static objects are constructed when needed. Also, they are always constructed even if they are never needed. Combining a static pointer to an object with a static function to reference the object and then creating the object, if necessary, defers creating the object until it is needed.
Use this class for resources that are limited to the same process (as opposed to a public resource that is used by more than one process via its name).
You can use this class as a static key to serialize access to a private resource. You can also use this class as a mechanism to ensure that the static resource is constructed prior to being used.
Some basic guidelines include the following:
Constructors & DestructorUse these members to construct and destruct objects of this class.
![]() |
public:
virtual ~IPrivateResource()
| IAccessError | The private resource object was not deleted. The semaphore handle may be invalid. |
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
IPrivateResource()
| IAccessError | The private resource object was not created. The memory may be exhausted or the semaphore handle limit on your platform may be exceeded. |
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
Lock/UnlockUse these functions to lock and unlock the resource.
![]() |
public:
virtual IPrivateResource& lock(long timeOut = - 1)
Locks can be be obtained multiple times on the same resource by the same thread. A corresponding number of unlocks must be performed to release the resource.
| IOutOfSystemResource | The request failed because of a lock time out. (DD) IAccessError Unexpected error while accessing underlying system object. |
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
virtual IPrivateResource& unlock()
| IAccessError | Unexpected error while accessing underlying system object. |
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
virtual ~IResource()
IResource()
virtual IResource& lock(long timeOut = - 1) = 0
virtual IResource& unlock() = 0
IPrivateSemaphoreHandle& handle()
void relockAll(long times)
long unlockAll()