Subject: RE: [SWIPL] Thread Create using Sockets

From: Jan Wielemaker <[email-masked]>
Date: Thu, 27 Sep 2001 13:57:11 +0200

On Wed, 26 Sep 2001, Douglas R. Miles wrote:
>Hi,
>
>The program below seems to work:
>
>But I am wondering if the socket_in/1,socket_out/1 and answer_yes are
>exclusive to each thread?

No, the database is shared between all threads.  You can use
thread_self/1 to label facts with the thread identifier.

>(Partially because I am new to using with_mutex/2.)
>
>Also is "threads,  % Free Up Complete Threads" necessary?  Is there a way I
>can call it that doesn't write to std*? 

threads/0 is a utility predicate meant for the toplevel to look at
the status or running threads.  Normally you have either a thread
waiting for the completion using thread_join or, if nobody is interested
in the completion you use the creation-option detached(true), which
makes the thread disappear completely once its main goal terminates
(succeeds, fails or raises an uncaught exception).

In some test applications I had a thread waiting for the others.
If a thread completed it sent a message to this waiting thread,
which in turn updated a list of running threads and joined the
completed thread.

	Regards --- Jan