Library Initialization and Cleanup


Each <ToolKit> in the Communications series contains two routines that must be invoked when using any class.

Failure to initialize a <ToolKit> produces different effects, depending on the library. In some cases, the library can work perfectly; at other times, the library can behave erroneously or cause an abnormal program termination.

The following are the methods for initializing an Recursion Software <ToolKit>.

Each Communications <ToolKit> uses a reference counting mechanism to track multiple initialization attempts, so it is safe to use all of the above techniques in the same application. Library initialization is not thread-safe and should only be performed by the primary, or main, thread.

Initialize a Library Using the Functional Interface

Each <ToolKit> provides a functional interface with the common format:

	os_init_library_toolkit();
	os_exit_library_toolkit();
	

where library is the name of the component.

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

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

void
main()
  {
  // Initialize Network<ToolKit>
  os_init_network_toolkit();

  cout << os_host::my_host() << endl;

  // Cleanup Network<ToolKit>
  os_exit_network_toolkit();
  }

Initialize a Library Using the Initialization Object

Each <ToolKit> contains an initialization object that provides automatic library initialization and cleanup. All initialization objects have the common name:

		class os_library_toolkit
		

where library is the name of the component.

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

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

void
main()
  {
  // Instantiate the Network<ToolKit> initialization object.
  os_network_toolkit initialize;

  // Display the current host information.
  cout << os_host::my_host() << endl;
  }
  

Initialize a Library Using Dynamic Link Libraries

For development on platforms that support dynamic link libraries (DLLs), automatic library initialization can occur through the DLL initialization routine. Although this technique is more convenient than the techniques discussed previously, it uses platform-specific features and can result in code that is not portable. Consequently, we recommend that you use one of the other initialization techniques discussed.

If your platform supports DLLs, automatic library initialization is provided by default. Consult the online release notes for more information about your specific platform.


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