Personal tools
You are here: Home Projects C++ Cfront releases Release 3.0.3 source lib task_SPARC TESTS t_create.C
Document Actions

t_create.C

by Michael L Powell last modified 2007-01-26 03:22

Click here to get the file

Size 1 kB - File type text/plain

File contents

#include <task.h>

/*
 * t_create.C
 * Example taken from "Appendix:  Example Programs" section of Shopiro
 * Extending the C++ Tasks System memo, Release Notes p 13-39.
 * Repeatedly creates a task and waits for it to terminate.
 * Can be used to time task creation and termination.
 */


class Child : public task	// user task declaration
{
public:
		Child(int);	// task constructor declaration
};


Child::Child(int i)		// user task constructor is task's "main"
: task("Child")			// argument to base class constructor
{
	resultis(i);		// terminate task execution
				// must NOT return
}

const int K = 66;

main()
{
	for (register int i = K; i--; ) {
		Child* c = new Child(i);	// create a task
		c->result();			// wait for it to terminate
		delete c;			// clean up
	}
	thistask->resultis(0);	// exit from main task
}
« December 2024 »
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: