Newsgroups: comp.os.parix
From: kba@hrz.tu-chemnitz.de (Karsten Baensch)
Subject: Re: Parix context
Organization: University of Technology Chemnitz, FRG
Date: 30 Oct 95 08:11:25 GMT
Message-ID: <4727of$61r@pyrrhus-f.hrz.tu-chemnitz.de>

renevey@ufps8.unifr.ch () writes:

>I'm quiet new in the Parix world and I would like to know if I can create a link
>between two contexts of the same processor.

>My code could have the following form:


>main_1(){
>	Execute(main_2,parix_environ);
>	link = ConnectLink(proc,1234,&error);
>	...
>}

>main_2(){
>	link = ConnectLink(proc,1234,&error);
>	...
>}

>Thanks for any suggestion
>Christian

Yes, you can, but you must create a new thread before Execute. Execute waits for the 
termination of the executed program, so there is no chance to make a ConnectLink in
the above way.

Here is a sample code. It creates a new thread in the first step. The thread function
performs the Execute. After that, an integer is exchanged between the two contextes.
Now it becomes interesting: Is it possible to send/receive a pointer between different
contextes? Yes it is! First context sends the pointer, second one receives it and
writes to it. First context prints value after WaitThread at the end of program.

Hope this helps you,

K.B.

file test1.c:
========================================================================================
#include <sys/root.h>

int NewContext()
{
	return Execute("test2.px", parix_environ);
}

int main()
{
	int Error;
	Thread_t *CreatedThread;
	LinkCB_t *ConnectedLink;

	int ToSend = 888;
	int *pToSend = &ToSend;
        
	if((CreatedThread = CreateThread(NULL, 10000, NewContext, &Error, NULL)) != NULL)
		LogError(EC_DEBUG, "main()", "Thread Created.\n");
	else
		LogError(EC_ERROR, "main()", "Could not create thread!\n");

	if((ConnectedLink = ConnectLink(PC_MyProcID, 1234, &Error)) != NULL)
		LogError(EC_DEBUG, "main()", "Link Created.");
	else
		LogError(EC_ERROR, "main()", "Could not create Link!\n");

	if(SendLink(ConnectedLink, &ToSend, sizeof(ToSend)) == sizeof(ToSend))
		LogError(EC_DEBUG, "main()", "Int sent.\n");
	else
		LogError(EC_ERROR, "main()", "Could not send int!\n");

	if(SendLink(ConnectedLink, &pToSend, sizeof(pToSend)) == sizeof(pToSend))
		LogError(EC_DEBUG, "main()", "Int pointer sent.\n");
	else
		LogError(EC_ERROR, "main()", "Could not send int pointer!\n");
                
	WaitThread(CreatedThread, &Error);

	LogError(EC_DEBUG, "main()", "Int has value=%d.\n", ToSend);

	return 0;
}
========================================================================================

file test2.c:
========================================================================================
#include <sys/root.h>

int main()
{
	int Error;
	LinkCB_t *ConnectedLink;

	int Received = 0;
	int *pToSend;
        
	if((ConnectedLink = ConnectLink(PC_MyProcID, 1234, &Error)) != NULL)
		LogError(EC_DEBUG, "main()", "Link Created.");
	else
		LogError(EC_ERROR, "main()", "Could not create Link!\n");

	if(RecvLink(ConnectedLink, &Received, sizeof(Received)) == sizeof(Received))
		LogError(EC_DEBUG, "main()", "Int received=%d.\n", Received);
	else
		LogError(EC_ERROR, "main()", "Could not receive int!\n");

	if(RecvLink(ConnectedLink, &pToSend, sizeof(pToSend)) == sizeof(pToSend))
		LogError(EC_DEBUG, "main()", "Int pointer received=%x.\n", pToSend);
	else
		LogError(EC_ERROR, "main()", "Could not receive int pointer!\n");

	LogError(EC_DEBUG, "main()", "Using int pointer.\n");
	*pToSend = 333;

	return 0;
}
========================================================================================



--
## Email: Karsten.Baensch@hrz.tu-chemnitz.de                                ##
## WWW:   http://www.tu-chemnitz.de/~kba/baensch.html                       ##
## Phone: (+49-) 0371/531-1379                                              ##
## Mail:  Technical University, Computing Services, 09107 Chemnitz, Germany ##

