Simple C-Linda with Posix Threads
=================================

Wong Weng Fai
31 Jan 1997


INTRO
-----

This a simple implementation of Linda using Posix threads. The prime motivation
is to use it to teach my parallel programming course. The program was written
for Posix threads and should run on any platform supporting Posix threads,
although I've only tried it on Sun Solaris 2. The only other thing that may
give problem if you attempt to port it is the variable argument library calls.


HOW TO USE IT
-------------

Very simple. You should have the following three files:

	1. linda.h - the C header file
	2. linda.c - the Linda functions in C
	3. primes.c - a simple Linda prime finder adapted from the p4-Linda
		      version

Just do the following:

	$ cc -c -O linda.c

This will produce the file "linda.o". To compile the prime finder example,
do:

	$ cc -o primes -O primes.c linda.o -lpthread -lm

"-lm" links in the math library and you can do without it if you don't need
math functions. But the "-lpthread" which brings in the Posix thread library
is compulsory.


PROGRAMMING NOTES
-----------------

1. The main program MUST call "linda_init()" before doing any Linda stuff.
It must also call "linda_end()" before exiting.

2. The Linda functions "in", "out", "rd", "inp" and "rdp" are implemented.
Excluded is the "eval" function and in its place is a "spawn" function.

3. "spawn" expects one argument - a void function which do not take in any
argument. A new thread will be spawned for evaluating this function.

4. Here's how you can use the "out" function:

	out (format-string, arguments, ...);

where format string looks like a C printf format-string except that it can
only take "%d" (integer), "%f" (float), "%c" (char) and "%s" (string). So
for example,

	out ("%s%d", "This is a test", j);

will put out a 2-tuple, the one field being a string and the second an
integer. The actual values for these fields are supplied in the arguments.

5. For "in", "rd", "inp" and "rdp", you can have "?" instead of "%" in the
field specifier to indicate fields that is to be binded to. So for example,

	in ("%s?d", "This is a test", &j);

will wait and match for a 2-tuple in the tuple space in which the first
field is to be the string "This is a test" and the second integer field of
the corresponding out tuple is written into the location pointed to be the
integer pointer "&j". For output fields, you must supply a valid pointer
which points to a location of the type specified.

6. Please see the file "primes.c" for example.


BUGS
----
This stuff was written in less than a day. So I expect tons of bugs. Please
send me the problematic program. My email is wongwf@iscs.nus.sg. You are free
to modify this poorly documented program anyway you see fit.
