From owner-freebsd-hackers@FreeBSD.ORG Sun Jun 20 02:14:59 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 408CF16A4CE; Sun, 20 Jun 2004 02:14:59 +0000 (GMT) Received: from ioskeha.hittite.isp.9tel.net (ioskeha.hittite.isp.9tel.net [62.62.156.27]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7522043D48; Sun, 20 Jun 2004 02:14:58 +0000 (GMT) (envelope-from clefevre-lists@9online.fr) Received: from pc2k (unknown [80.119.159.86]) by ioskeha.hittite.isp.9tel.net (Postfix) with SMTP id 3ABEF14B5D7; Sun, 20 Jun 2004 04:17:44 +0200 (CEST) Message-ID: <008901c4566c$610d1300$7890a8c0@dyndns.org> From: "Cyrille Lefevre" To: Date: Sun, 20 Jun 2004 04:14:53 +0200 Organization: ACME MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 cc: hackers@freebsd.org Subject: -lthr vs. -pthread X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 20 Jun 2004 02:14:59 -0000 Hi, I'm currently working on enhancements to ps w/ "Garance A Drosehn". I've just added some thread related stuffs and to see them, I'm using the following program : #define _REENTRANT #include #define NUM_THREADS 5 #define SLEEP_TIME 10 void *sleeping(void *); pthread_t tid[NUM_THREADS]; int main(int argc, char *argv[]) { int i; for (i = 0; i < NUM_THREADS; i++) pthread_create(&tid[i], NULL, sleeping, (void *)SLEEP_TIME); for (i = 0; i < NUM_THREADS; i++) pthread_join(tid[i], NULL); printf("main() reporting that all %d threads have terminated\n", i); return (0); } void * sleeping(void *arg) { int sleep_time = (int)arg; printf("thread %d sleeping %d seconds ...\n", thr_self(), sleep_time); sleep(sleep_time); printf("\nthread %d awakening\n", thr_self()); return (NULL); } then, I compile this one in 2 way : # cc -o thread thread.c -lthr and # cc -pthread -o pthread thread.c here is some of the "new ps" outputs : "lwp" is the thread id and "nlwp" the the number of threads. -q switch in posix mode (aka SystemV) and -C select processes by name (a la pgrep). # ./thread& sleep 1; ps -H -O lwp,nlwp -qC thread (thread, using -H) PID LWP NLWP TTY TIME COMMAND 85146 100005 6 ttyp0 00:00:00 thread 85146 100004 6 ttyp0 00:00:00 thread 85146 100003 6 ttyp0 00:00:00 thread 85146 100002 6 ttyp0 00:00:00 thread 85146 100001 6 ttyp0 00:00:00 thread 85146 85146 6 ttyp0 00:00:00 thread # ./pthread& sleep 1; ps -H -O lwp,nlwp -qC thread (pthread, using -H) PID LWP NLWP TTY TIME COMMAND 96689 100002 2 ttyp0 00:00:00 pthread 96689 96689 2 ttyp0 00:00:00 pthread is it normal that -pthread only forks only 1 thread where -lthr forks 5 of them ? # ./thread& sleep 1; ps -O lwp,nlwp -qC thread (thread ot pthread, not using -H) PID LWP NLWP TTY TIME COMMAND 73718 100005 6 ttyp0 00:00:00 thread is it normal that the selected process is the last forked thread and not the thread owner (father) ? PS : using -lc_r, there is no thread at all, but I suppose this is an expected behaviour. CC -current and -hackers Cyrille Lefevre. -- mailto:clefevre-lists@9online.fr