From: Mark Jones
Subject: Solution!?  Foreign input interface with Sun common lisp program
Date: 
Message-ID: <1992Jul6.190642.15449@udel.edu>
A while ago I posted a problem with hooking up a C++ screen interface 
system to a large lisp project written in Sun Common Lisp.

>I tried using InterProcess Communication:
>  I wrote two small C programs that used the message handling functions i
>  msgget and msgrcv.  One would
>  put the message out to be read, the other would get the message.
>  I tested them at the operating system level (without lisp) and they 
>  worked.  I could start the get program in one window & it would
>  wait until I did the put in another window & the data would exchange.
>
>  The next step was to call the get function from lisp. 
>  I used the Sun Common Lisp foreign function interface to allow the 
>  lisp code to call the get function.
>
>  I could get the foreign function interface to work as long as I was
>  not doing InterProcess Communication!  
>  I got the help of someone who knows the operating system pretty well.
>  His conclusion was that Sun Common Lisp is relying upon and manipulating
>  the very things that we were using to send messages.
>  It seems that Lisp was mucking around with system signals.

This signal problem was later confirmed and elaborated on by some
kind net people.

The project is not completely settled, but there is some good news:

It seems that we were getting problems with using the system's busy-wait
at the get message call.

Using our own (simple) busy wait, and not requesting a busy wait 
from the system has made the behavior reliable.

Here is the receive call we now use:

  while((ct =  msgrcv(msgid_ss, &msg, MSGBUFSIZE, 0L, 1))<0) ;

   ct : int,  it is set to -1 when no message is received (thus the busy wait).
   msgid_ss : int , the identifier of the message channel. 
   msg : a structure which holds the message
   MSGBUFSIZE :  a constant for the size of the buffer
   OL :  I believe this is a flag that is specific to our system.

   I am hardly an expert on message sending.  My only point is that
   using our own busy wait seems to help.

I hope this is of some help.
-mark (·····@udel.edu)