Newsgroups: comp.sys.transputer
From: ashdown@mpr.ca (Scott Ashdown)
Subject: Re: Process id's with the INMOS C Toolset ?
Organization: MPR Teltech Ltd., Burnaby, B.C., Canada
Date: Mon, 28 Nov 1994 19:34:46 GMT
Message-ID: <1994Nov28.193446.23409@mprgate.mpr.ca>

In article <MUENKEL.94Nov24153545@daedalus.tnt.uni-hannover.de> muenkel@daedalus.tnt.uni-hannover.de (Heiko Muenkel) writes:
>Is it possible to get a process id (or something similar) for
>subprocesses in a program written with the INMOS C Toolset to identify
>the process in subroutines ?
>
>What I want to do is something like the following: I want to start 3
>different subprocesses with the C function ProcRun. The functions and
>subfunctions of the processes should be able to determine in which
>process they are called. Is this possible without using a function
>parameter? 

Okay, this is kind of cheating, but you could do the following:

Have a module with two interface functions and a single "internal" task.

Initialize() - Pseudocode

1. Start up a task (runs "inside" the module).
2. Create semaphores/channels if you don't want to make them static ("mutex"
   should be init'd to 1).

GetMyPID() - Pseudocode

1. SemWait(mutex). (So we can use the moduel with multiple client tasks)
2. ChanOutInt(Chan_A, 1) (second arg is arbitrary).
3. Typecast and return the value of ChanInInt(Chan_B).
4. SemSignal(mutex).

Task main body - Pseudocode

1. Task uses ProcAlt() to wait on a channel Chan_A.
2. When the task returns from the call to ProcAlt(), it should read the
   value of the channel word (i.e. the location pointed to by the channel
   point Chan_A) This will contain the process ID of the task that just
   called GetMyPID().
3. ChanInInt(Chan_A) to release the client task from the ChanOutInt() in
   GetMyPID().
4. ChanOutInt() the value read from the channel word.
5. Go back to step 1.

Comments on this are, of course, welcomed.




-- 
Scott Ashdown
Engineer, MPR Teltech Ltd.
Burnaby, British Columbia, Canada.
ashdown@mprgate.mpr.ca

