Example #1
0
int main()
{
    CLExecutiveFunctionProvider *myfunction = new CLMyFunction();
    CLExecutive *pThread = new CLThread(myfunction);

    SPara *p = new SPara;
    p->Flag = 3;
    pthread_mutex_init(&(p->mutex), 0);

    pThread->Run((void *)p);

    pthread_mutex_lock(&(p->mutex));

    p->Flag++;
    cout << p->Flag << endl;

    pthread_mutex_unlock(&(p->mutex));

    pThread->WaitForDeath();

    pthread_mutex_destroy(&(p->mutex));
    delete p;

    delete pThread;
    delete myfunction;

    return 0;
}
Example #2
0
int main()
{
    CLExecutiveFunctionProvider *myfunction = new CLMyFunction();
    CLExecutive *pThread = new CLThread(myfunction);

    SPara *p = new SPara;
    p->Flag = 3;

    pThread->Run((void *)p);

    sleep(2);

    {
	CLCriticalSection cs(&(p->mutex));

	p->Flag++;

	cout << p->Flag << endl;
    }

    pThread->WaitForDeath();

    delete p;

    delete pThread;
    delete myfunction;

    return 0;
}
Example #3
0
int main(){
	CLExecutiveFunctionProvider *printer = new CLParaPrinter();
	CLExecutive *pThread = new CLThread(printer);
	
	pThread->run((void*)2);
	pThread->waitForDeath();
	 
	return 0;
}
Example #4
0
int main()
{
	CLExecutive *p = new CLProcess(new CLProcessFunctionForExec, true);
	if(p->Run((void *)"./b.out hello world").IsSuccess())
	{
		p->WaitForDeath();
	}

	return 0;
}
Example #5
0
int main()
{
	if(!CLLibExecutiveInitializer::Initialize().IsSuccess())
	{
		cout << "Initialize error" << endl;
		return 0;
	}

	CLExecutive *p = new CLProcess(new CLProcessFunctionForExec, false);
	if(!p->Run((void *)"./test/a.out hello world").IsSuccess())
		cout << "Run error" << endl;

	if(!CLLibExecutiveInitializer::Destroy().IsSuccess())
		cout << "Destroy error" << endl;

	return 0;
}
Example #6
0
int main()
{
    CLExecutiveFunctionProvider *printer = new CLParaPrinter();
    CLExecutive *pThread = new CLThread(printer);

    pThread->Run((void *)2);

    CLStatus s = pThread->Run();
    if(!s.IsSuccess())
	cout << "Run error" << endl;

    pThread->WaitForDeath();

    delete pThread;
    delete printer;

    return 0;
}
int main_share_mem1()
{
	try
	{
	CLSharedMemory sm("SharedMemoryFortest",sizeof(int));
	int *pAddr = (int *)sm.GetAddress();
	*pAddr = 123456;
	CLCoordinator *my = new CLRegularCoordinator;
	CLExecutive *process = new CLProcess(my,new CLProcessFunctionForExec,true);
	if(!process->Run((void*)"./shm.out").IsSuccess())
	{
		std::cout << "In main(),process->Run error." << std::endl;
	}
	process->WaitForDeath();
	}
	catch(const char *s)
	{
		std::cout <<s<<std::endl;
	}
	return 0;
}
Example #8
0
int main()
{
	int *paddr = (int *)-1;
	int shmid = -1;

	try
	{
		if(!CLLibExecutiveInitializer::Initialize().IsSuccess())
		{
			cout << "Initialize error" << endl;
			return 0;
		}
		
		int fd = open("/tmp/a.txt", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
		if(fd == -1)
		{
			cout << "open error" << endl;
			throw CLStatus(-1, 0);
		}

		close(fd);

		key_t key = ftok("/tmp/a.txt", 0);
		if(key == -1)
		{
			cout << "ftok error" << endl;
			throw CLStatus(-1, 0);
		}

		shmid = shmget(key, 4, IPC_CREAT);
		if(shmid == -1)
		{
			cout << "shmget error" << endl;
			throw CLStatus(-1, 0);
		}

		paddr = (int *)shmat(shmid, 0, 0);
		if(paddr == (int *)-1)
		{
			cout << "shmat error" << endl;
			throw CLStatus(-1, 0);
		}

		*paddr = 5;

		CLExecutive *process = new CLProcess(new CLProcessFunctionForExec, true);
		if(!(process->Run((void *)"./test/a.out")).IsSuccess())
			cout << "process Run error" << endl;
		else
			process->WaitForDeath();

		throw CLStatus(0, 0);
	}
	catch(CLStatus& s)
	{
		if(paddr != (int *)-1)
		{
			shmdt(paddr);
		}

		if(shmid != -1)
		{
			shmctl(shmid, IPC_RMID, 0);
		}

		if(!CLLibExecutiveInitializer::Destroy().IsSuccess())
			cout << "Destroy error" << endl;

		return 0;
	}
}