You might either want to use a lock and state variable or for more
flexibility and efficiency look at the waitqueue/condition variable stuff -
These provides allow you to have one or more threads wait using
condition-wait until another thread notifies them using
condition-notify. For example I am using this to have a thread which
carries out tasks in the background. The tasks are put on a queue by
other threads, which then notify the processing thread. These threads
may then return immediately, or if they need the result they can wait
until notified by the processing thread.
>>>>> "Shyamal" == Shyamal Prasad <firstname.lastname@example.org> writes:
Shyamal> I need some help understanding how to wait for a SBCL
Shyamal> thread to be done (i.e. do a thread_join operation).
Shyamal> Starting the thread is easy, e.g.
Shyamal> (sb-thread:make-thread (lambda () (write-line "Hello,
Shyamal> I can then look at all threads with
Shyamal> sb-thread:list-all-threads and see if specific thread is
Shyamal> running with sb-thread:thread-alive-p.
Shyamal> However, I am unable to see an obvious way to do a
Shyamal> blocking wait for a thread to finish....many google
Shyamal> searches got me nowhere.
Shyamal> So I looked in the SBCL source and, as far as my little
Shyamal> mind can go, it seems the thread code actually does not
Shyamal> provide a way for me to do this (in
Shyamal> src/code/target-thread.lisp all handle-thread-exit does
Shyamal> is remove the thread from *all-threads* so it can be
Shyamal> gc'ed when appropriate; no hooks to watch for it that I
Shyamal> could see, and the underlying pthread join seems
Shyamal> unexposed to the lisp programmer).
Shyamal> So...what am I missing? Or do I really need to roll my
Shyamal> own sychronization macros to wrap each thread start/stop
Shyamal> with some condition variables?
Shyamal> Cheers! Shyamal
Shyamal> PS: I don't read the SBCL mailing list, so I thought I'd
Shyamal> try here first.
John A.R. Williams
PGP key: 6606795A185C384C