Simple C-Linda with Posix Threads

Brought to you by W. F. Wong


This a simple implementation of Linda using Posix threads. The prime motivation is to use it to teach my parallel programming course. My inspiration came from p4-Linda. 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

Simple. Pick up the file linda.tar.gz, then unzip and untar it in one go by:

	$ gunzip -c linda.tar.gz | tar xvf -

You should have the following three files in a new sudirectory named linda:

  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 found in the public domain
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 examples on how the above functions are to be used.


This stuff was written in less than a day - and under the influence of Kurt Cobain and Nirvana, and a cup of strong Japanese green tea. So I expect tons of bugs. Please send me the problematic program. You are free to modify this poorly documented program anyway you see fit - just let me know if you've done something interesting with it.

Last updated 31 January 1997 - wongwf