Thank you for the response, Jan.
I have updated SWI Prolog to the latest stable version for Mac OS as suggested. This has not solved the problem.
The short answers to your questions:
The interaction with “iapp” is spread over multiple client HTTP requests.
I run the Prolog server in a terminal which serves as a message console.
The Prolog server program starts http_server and the main program then sleeps (for a long time, repeatedly) or optionally returns to Prolog top level so I can do makes while developing/debugging and can examine data structures.
For the ongoing interaction of clients with instances of iapp I have an iapp session.
When an HTTP request is received that requires a session with “iapp”, the server starts an “iapp” process and successfully exchange several commands and responses with it over the pipes.
Other clients of the server can similarly initiate distinct sessions with other instances of “iapp”.
The “iapp” process session is left to continue as it must be used again for future HTTP calls from the same client for which it was created and the process id of iapp is returned to the client as an identifier for future interaction with the iapp session.
The process id of iapp along with the pipe descriptors to communicate with it are stored in a unit clause
of a dynamic predicate.
When a client makes an HTTP request that requires interaction with “iapp” the caller provides the process id of the previously established session.
The server thread handling the request looks up (in the dynamic predicate) the in and out streams associated with the relevant iapp process id.
The server thread then attempts to continue the dialog with iapp on behalf of the client.
This is where the problem occurs.
The interaction with iapp hangs on the first read.
Subsequent HTTP requests to the server complete successfully, provided they do not involve interaction of the server thread with “iapp”.
In the case of the version that enters top level interactive loop after starting the http_server,
the hang is on the very first read on the in pipe from iapp. It seems like the outstanding read
from the terminal in the main thread is interfering with the read on the pipe by the server thread.
But doing some interaction from the keyboard unfreezes that hang (once).
Then the interactions with iapp proceed normally for the initial Http request.
Subsequent http requests that do not involve interaction with iapp complete properly.
However, the next http request that requires interaction with iapp hangs and the interactive terminal
session also becomes unresponsive. Curiously though the http server continues to respond
to “innocuous” requests. I.e. requests that do not involve interaction with an instance of iapp
succeed, including ones that initiate entirely new instances of iapp!
But, in the same way, new requests for followup actions with the new instances of iapp also hang.
A related question: it appears that i have to reopen connection (socket, setsockopt, connect from C program) for every interaction (HTTP api call) with server.