So directly to your question:
Where can i find an implementation of the coordination language linda in c?
Here: http://www.comp.nus.edu.sg/~wongwf/linda.html
You can download it and use it!
If you download it you should get this:
linda //dir
|
| - linda.c //file
| - linda.h //file
| - primes.c //file
| - README.txt //file
But you have to know:
- You must call
linda_init()
before you do linda stuff
- You must call
linda_end()
before exiting
- There is no
eval()
function but you can use spawn()
- The library
varargs.h
is outdated! So i would recommend you to use: stdarg.h
- So that means it could be that you have to rewrite stuff!
So there is only one thing todo!
Download it and get started!
EDIT:
Another way you could go is to download a Linda-C
compiler and write your programs in Linda-C (*.clc
).
So but back to library from above:
I got a program working with linda in c with this library!
I have: GNU GCC compiler(tdm64-1) 4.7.1 MinGW64
What you have to look out for:
- In
linda.h
you have to change the include sys/varargs.h
to stdarg.h
since varargs is outdated!
- That means also that you have to change in
linda.c
all va_arg()
calls and change the following type:
float
-> double
char
-> int
- After you have done that you should be able to compile
linda.c
to linda.o
with this command line:
gcc -c -O linda.c
(Also it could be that you have to direct to the gcc.exe
so that the command gcc
is known in Windows cmd
)
So as an example:
Path to gcc compiler
:
"C:\Program Files (x86)\Dev-Cpp\MinGW64\bin"
Path to linda library
:
"C:\Users\xy\Downloads\linda\linda"
So now if you open cmd
and type in: gcc --version
and it's not found you have to direct to the gcc.exe
file like this (otherwise your fine and you don't have to direct to the compiler dir):
cd "C:\Program Files (x86)\Dev-Cpp\MinGW64\bin"
So if your in the directory
where gcc.exe
is located you should be able to execute that command: gcc --version
And from there you can execute the command to create linda.o
! Which looks like this in this example:
gcc -c -O C:\Users\xy\Downloads\linda\linda\linda.c
If all worked out! You should end up with the file linda.o
in your compiler directory
And now with the file linda.o
you can compile primes.c
(Which is in this library as an example) and get a linda
programm in c
working! with the following line:
gcc -o C:\Users\xy\Downloads\linda\linda\primes -O C:\Users\xy\Downloads\linda\linda\primes.c C:\Users\xy\Downloads\linda\linda\linda.o -lpthread -lm
With this line you should end up with the .exe
file: primes.exe
! Which you can copy in the compiler directory and execute! If you don't have it in this dir then lpthreadGC2_64.dll
is unknown and it can't be executed!
- Few side notes to the compiling of this example:
- lpthread -> pthread library
- lm -> math library
- Also i would recommend you to add the following line in the
primes.c
file at the end so that if you execute it, the window does not close instant: system("pause");
- Also for your problem that with this library you can't use
eval()
there are a few workarounds/ solutions:
- You can make a
for
loop and call your functions multiple times! (Since the function you call with spawn()
has to have void
as return type
)
- You can define a constant with:
#define CALLS 5
and use this in the function itself for the commands to execute in a for
loop or also in the main
function to call spawn()
multiple times
- I think there are more ways to solve this!
So all that said. Your program should look something like this:
#include "linda.h"
#define NUM 5
void worker() {
int i;
for (i = 0; i < NUM; i++)
out("%s", "hello, world");
}
int main() {
int result;
spawn(worker);
in("%s", "hello, world");
in("%s", "hello, world");
in("%s", "hello, world");
in("%s", "hello, world");
in("%s", "hello, world");
in("%s?d", "worker", &result);
system("pause");
return 0;
}
Hope this helps you!
Cheers