op_pro_destroy()

Abstract

Destroys a dynamically created process.

Syntax

op_pro_destroy (pro_handle)
Argument Type Description
pro_handle Prohandle Process handle of the process that is to be destroyed

Return Type

Compcode

Completion code indicating whether or not the Simulation Kernel successfully destroyed the process. This return code can be compared to the constants OPC_COMPCODE_SUCCESS and OPC_COMPCODE_FAILURE to determine if the process destruction was successful.

Example

Excerpt from: example model (models/std/x25); external file (x25_funcs.ex.c); function (x25_channel_free()).

/* Extract the group and channel indices from the channel number */
group = (chan_num & X25C_MASK_GROUP) >> X25C_SHIFT_GROUP;
index = (chan_num & X25C_MASK_LCHAN) >> X25C_SHIFT_ICHAN;

if (root [group] != OPC_NIL)
	{
	/* Get the pointer to the channel. */
	chan_ptr = root [group][index];
	if (chan_ptr != OPC_NIL)
		{
		/* Destroy the sub-process. */
		if (op_pro_destroy (chan_ptr->process) == OPC_COMPCODE_FAILURE)
			{
			x25_warning (“Unable to destroy channel process.”);
			}

		/* Deallocate the memory for the channel structure. */
		/* First the string pointers. */
		op_prg_mem_free (chan_ptr->local_addr);
		op_prg_mem_free (chan_ptr->remote_addr);
		op_prg_mem_free (chan_ptr->loc_app_name);
		op_prg_mem_free (chan_ptr->rem_app_name);

		/* Deallocate the channel itself. */
		op_prg_mem_free (chan_ptr);

		/* Mark the entry as free, so that a future connection */
		/* can use this channel. */
		root [group] [index] = OPC_NIL;
		}
}

Details

This KP allows a process to destroy any other dynamic process that is owned by the same module (thus, the root process is the only process that cannot be destroyed in a given module). (A dynamic process is one created via the KP op_pro_create(); dynamic processes can be removed from the model at any time during the simulation.)

Proper termination of a process generally involves deallocation of dynamic memory that the process may have allocated, but may also include actions specific to the modeling application (such as reporting the value of a statistic accumulated during the process’ history). Process models have a special section of logic devoted to the processing that occurs when they are destroyed. This section is the process model’s Termination Block and the code contained within it is invoked directly by the Simulation Kernel when the process is destroyed. State and temporary variables may be used in this section of code.

A process may destroy itself, in which case it does not return. Therefore, no actions will be performed by a process after it destroys itself, with the exception of actions specified in the Termination Block.

Note: The Kernel assumes no responsibility for deallocation of parent-to-child or argument memory.

Purpose

Supports the removal and deallocation of dynamically created processes. This provides the ability to maintain active only those processes necessary to the correct operation of a processor or queue.

Errors

  • Program Abort: KP requires process context.
  • Program Abort: segmentation violation. (due to a malformed process handle)
  • Recoverable Error: Process handle is invalid.
  • Recoverable Error: Process handle is for destroyed process (<proc_id>).
  • Recoverable Error: Process handle is for remote process (<proc_id>).
  • Recoverable Error: Process handle is for root process (<proc_id>).
  • Recoverable Error: Process handle is for active process (<proc_id>).

Reference

本站文档由 北京智网畅联科技有限公司 整理、翻译并提供 · Documentation compiled and provided by Beijing ZNetLink Technology Co., Ltd.

交流群 · QQ Group:OPNET/智网妙算网络仿真交流群(群号 486383494)

原文档 © 2017 Riverbed Technology · 本站为公益翻译,由 AI 辅助完成,请仔细甄别

Original documentation © 2017 Riverbed Technology. Community translation, AI-assisted. Contact: jiazequn@znetlink.com