Re: A problem involving threads and http streams

Jan Wielemaker <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
On 09/14/2013 12:39 PM, Torbj�rn Lager wrote:
> Dear all,
>
> In connection with my work on Pengine I have run into an issue I don't
> understand.
>
> The help you see the problem I have attached a zip archive with three
> small files, two servers and one client:
>
> test_server_buggy.pl
> test_server_working.pl
> test_client.pl
>
> The difference between test_server_working.pl and test_server_buggy.pl
> is very small. In test_server_working.pl I use a message queue with a
> hard coded name 'out'. This works but isn't good enough since my
> application requires that the name of the message queue is unique. In
> test_server_buggy.pl I use http_session_assert/1 and
> http_session_data/1 to remember the unique message queue name as given
> by message_queue_create/1. This doesn't work, since an error
>
> error(existence_error(stream,<stream>(0x7fb2d9201fb0)),context(http_stream:is_cgi_stream/1,_G132))
>
> is thrown. I don't understand why this happens and how to work around it.

Normally, you'd find this using the graphical tracer and Edit/Exceptions
menu.  There you specify that you want to trap the debugger on all
exceptions and then you run the goal.

The problem is with this:

output(Term) :-
     http_session_data(out(Out)),
     thread_send_message(Out, Term).

This thing is executed in a new thread that is not connected to
the session.  It calls http_session_data/1, which uses the CGI
stream to find the session id, but there is no CGI stream for
this thread.  So, you need to start this as

	thread_create(test_goal(Out), _, [])

and then somehow make sure the Out remains accessible in the thread,
either by passing it, putting it in a global variable or putting it
in a thread-local predicate.

	Cheers --- Jan


> I use the latest SWI Prolog developer version on a Mac.
>
> Best regards,
> Torbj�rn
>

_______________________________________________
SWI-Prolog mailing list
[email protected]
https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.