about
3/03/2022
System-wide Resources

BasicBites - System-wide Resources

Global resources, kernel objects

All the common operating systems, Windows, linux, Unix, and macOS, provide ways to create and access system-wide resources. That is, resources that can be accessed by more than one scope in a given program without passing references and by more than one program. Typical examples are files, mutexes, and memory-mapped file pages. Each shared resource is represented by a named kernel object. Here we are not concerned with platform components like memory and CPUs. Rather, we focus on objects that our programs create to provide data and functionality shared between programs, including objects created by the platform at startup or when critical events occur. Sharing may result in collisions - concurrent reads and writes from different threads or processes. This is usually managed with shared named mutexes. However, other possibilities exist. I've written a concurrent file access library in C++ that uses failure of a file open to sleep and retry. In managed code the same retry strategy can be implemented by catching managed exceptions on file operations. User libraries can also be shared by compiling to a sharable binary that is loaded at program load time if not already loaded. This only works effectively for languages that have a standardized binary format. The platform loader depends on that format to resolve function references between the main executable and loaded library. This works well for C++, C#, and Java. Rust however has not yet standardized a binary format, so loading only works if the executable and library are both compiled with the same binary format. Rust makes no guarantees that the format will remain fixed between versions of the compiler. Depending on a standard binary format is important for cases where a library is intended to be provided as an expected resource, perhaps for several years, not compiled with each application.

Example Kernel Objects:

Windows provides:
  • Acess token, Change notification, Event, Event log, I/O completion port
  • File, File mapping, Communications device, Socket, Console input, Console screen buffer, Pipe
  • Desktop, Heap, Job
  • Module, Process, Thread, Timer
  • Mutex, Semaphore

Consequences:

Platforms that provide system-wide resources enable creation of global facilities, for example:
  • Test Harness - used by development teams for continuous integration and testing
  • Logging - persistent error reports for applications with lifetime not tied to the logging applications
  • Application messaging
  • System health monitoring
Note that the examples cited above will be likely to work across a network of the local and remote platforms. Communication between platforms will probably use sockets for connections, perhaps wrapped in objects defined in a communication library.

References:

  1. Kernel Objects
  Next Prev Pages Sections About Keys