[q-lang-users] OpenBSD, threading
Brought to you by:
agraef
From: <mip...@ya...> - 2004-02-02 02:14:35
|
(Sorry in advance for any bizarre formatting -- still not used to yahoo's email system.) ;; OpenBSD ./configure --with-x --with-gmp="-lgmp -L/usr/local/lib" \ --with-gmp-includes=-I/usr/local/include --with-rl --with-pthread \ --with-tk="-ltcl83 -ltk83 -L/usr/local/lib" \ --with-tk-includes=-I/usr/local/include/tcl8.3 \ -I/usr/local/include/tk8.3 Everything compiles fine expect for modules/clib/clib.c -- there I had to add an "#include <unistd.h>", since something apparently failed to define HAVE_UNISTD_H (I also get many complaints about including malloc.h instead of stdlib.h, but nothing seems hurt by this.) ;; threading I just started programming with Q last night, so perhaps I miss something obvious (I certainly don't understand all of Q's 'rewriting rules' semantics, though these fascinate me.) I've tried to implement a simple concurrency-oriented 'echo' server, with a thread per client, and have had a great of trouble with this. (With Q using OS-level POSIX threads, I know that this design won't work in the long run anyway -- I just wanted to see how it'd work, and the Q manual's UDP code inspired me.) My code: server P = thread (server_loop FD) where FD:Int = socket AF_INET SOCK_STREAM 0, () = bind FD ("localhost",P), () = listen FD 4; = perror "server" otherwise; server_loop FD = printf "Got connection from: %s:%d\n" (H,P) || server_loop FD where (C:Int,(H,P)) = accept FD, T = thread (echo_loop C); = writes "Loop.\n" || server_loop FD otherwise; echo_loop FD = printf "(loop %d)\n" FD || echo_loop FD where MSG = recv FD 0 4096, () = echo FD MSG (bcmp MSG (bytestr "")); = closesocket FD || cancel this_thread otherwise; echo FD MSG 0 = error; echo FD MSG _ = yield || send FD 0 MSG || (); I've already uglified it a bit, trying to figure out the problem. On my machine I get the "Got connection from: ..." message on a connection, and on subsequent connections, but the (thread (echo_loop C)) never seems to happen. I know that everything but the threading works, because I had this server running in exactly this form before I started trying to make it multithreaded. So what do I miss? ________________________________________________________________________ BT Yahoo! Broadband - Free modem offer, sign up online today and save £80 http://btyahoo.yahoo.co.uk |