Library Initialization and Cleanup


There are two methods for initializing Platform<ToolKit> for UNIX. Both methods require developer participation.

Failure to initialize the toolkit produces different effects, and in some instances can cause an abnormal program termination. Platform<ToolKit> for UNIX uses a reference counting mechanism to track multiple initialization attempts, so it is safe to use both techniques in the same application. Library initialization is not thread safe, and should only be performed by the primary, or main, thread.

Initializing a Library Using the Functional Interface

Platform<ToolKit> for UNIX provides a functional interface.

	os_init_unix_toolkit();
	os_exit_unix_toolkit();
	

The following code fragment shows how the functional interface can be used with the Platform<ToolKit> for UNIX.

#include <ospace/unix.h>

void
main()
  {
  // Initialize Platform<ToolKit> for UNIX
  os_init_unix_toolkit();

  // Invoke a Platform<ToolKit> for UNIX method.
  os_this_process::sleep( 1 );

  // Cleanup Platform<ToolKit> for UNIX
  os_exit_unix_toolkit();
  }

Initializing a Library Using the Initialization Object

Platform<ToolKit> for UNIX also contains an initialization object that provides automatic library initialization and cleanup.

		class os_unix_toolkit
 

The following code fragment shows how the initialization object can be used with Platform<ToolKit> for UNIX.

#include <iostream>
#include <ospace/unix.h>

void
main()
  {
  // Instantiate the Platform<ToolKit> for UNIX initialization object.
  os_unix_toolkit initialize;

  // Display the machine type.
  cout << "machine: " << os_system::machine() << endl;
  }
  

Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.