Re: -lthr vs. -pthread
At 4:14 AM +0200 6/20/04, Cyrille Lefevre wrote: is it normal that the selected process is the last forked thread and not the thread owner (father) ? I committed the changes, so people can try this if they want. Example: (48) ps -HO lwp,nlwp PIDLWP NLWP TT STAT TIME COMMAND 1870 18701 ?? SL 0:00.13 sshd: [EMAIL PROTECTED] (sshd) 1871 18711 p3 SLs0:00.09 -bash (bash) 2535 126 p3 SL+0:00.00 ./cyr-thread 2535 116 p3 SL+0:00.00 ./cyr-thread 2535 146 p3 SL+0:00.00 ./cyr-thread 2535 25356 p3 SL+0:00.00 ./cyr-thread 2535 106 p3 SL+0:00.00 ./cyr-thread 2535 136 p3 SL+0:00.00 ./cyr-thread (49) ps -O lwp,nlwp PIDLWP NLWP TT STAT TIME COMMAND 1870 18701 ?? S 0:00.13 sshd: [EMAIL PROTECTED] (sshd) 1871 18711 p3 Ss 0:00.09 -bash (bash) 2535 146 p3 S+ 0:00.00 ./cyr-thread When the -H is not requested, why does process 2535 show up as thread-ID #14 instead of #2535? Is that something that we need to change when copying info into kproc_info ? Or is that perfectly reasonable? I have not worked with threaded apps, so I am not sure what people would be expecting here. -- Garance Alistair Drosehn= [EMAIL PROTECTED] Senior Systems Programmer or [EMAIL PROTECTED] Rensselaer Polytechnic Instituteor [EMAIL PROTECTED] ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: -lthr vs. -pthread
this is a question for marcel, but basically this may change. In current code the thread_id of the first thread is set to be equal to the PID. Marcel and I have discussed reworking the thread_id code and in the new code this will possibly not be true. Under KSE teh original thread has probably exited.. and the one availabel to run is number 14. Under KSE threads are ephemeral, and come-and go as needed. (so the ID actually doesn't mean anything of rgeat significance) On Sun, 20 Jun 2004, Garance A Drosihn wrote: At 4:14 AM +0200 6/20/04, Cyrille Lefevre wrote: is it normal that the selected process is the last forked thread and not the thread owner (father) ? I committed the changes, so people can try this if they want. Example: (48) ps -HO lwp,nlwp PIDLWP NLWP TT STAT TIME COMMAND 1870 18701 ?? SL 0:00.13 sshd: [EMAIL PROTECTED] (sshd) 1871 18711 p3 SLs0:00.09 -bash (bash) 2535 126 p3 SL+0:00.00 ./cyr-thread 2535 116 p3 SL+0:00.00 ./cyr-thread 2535 146 p3 SL+0:00.00 ./cyr-thread 2535 25356 p3 SL+0:00.00 ./cyr-thread 2535 106 p3 SL+0:00.00 ./cyr-thread 2535 136 p3 SL+0:00.00 ./cyr-thread (49) ps -O lwp,nlwp PIDLWP NLWP TT STAT TIME COMMAND 1870 18701 ?? S 0:00.13 sshd: [EMAIL PROTECTED] (sshd) 1871 18711 p3 Ss 0:00.09 -bash (bash) 2535 146 p3 S+ 0:00.00 ./cyr-thread When the -H is not requested, why does process 2535 show up as thread-ID #14 instead of #2535? Is that something that we need to change when copying info into kproc_info ? Or is that perfectly reasonable? I have not worked with threaded apps, so I am not sure what people would be expecting here. -- Garance Alistair Drosehn= [EMAIL PROTECTED] Senior Systems Programmer or [EMAIL PROTECTED] Rensselaer Polytechnic Instituteor [EMAIL PROTECTED] ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED] ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: -lthr vs. -pthread
On Sun, Jun 20, 2004 at 05:07:56PM -0700, Julian Elischer wrote: this is a question for marcel, but basically this may change. In current code the thread_id of the first thread is set to be equal to the PID. Marcel and I have discussed reworking the thread_id code and in the new code this will possibly not be true. Yes. We need to be sure however that we don't break core file creation. Historically the PRSTATUS note in the core file has the process ID. The current thread LWP allocation allows us to put the Thread ID in the note and have as many notes as there are threads. Non-threaded processes will create core files that are compatible with older tools. If we change the LWP allocation, we will break this and should probably use LWPSTATUS notes for the thread states and use the PRSTATUS note for the process state. In any case, this requires modifications to binutils, so needs to be coordinated. -- Marcel Moolenaar USPA: A-39004 [EMAIL PROTECTED] ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
-lthr vs. -pthread
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 pthread.h #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) PIDLWP NLWP TTYTIME COMMAND 85146 156 ttyp0 00:00:00 thread 85146 146 ttyp0 00:00:00 thread 85146 136 ttyp0 00:00:00 thread 85146 126 ttyp0 00:00:00 thread 85146 116 ttyp0 00:00:00 thread 85146 851466 ttyp0 00:00:00 thread # ./pthread sleep 1; ps -H -O lwp,nlwp -qC thread (pthread, using -H) PIDLWP NLWP TTYTIME COMMAND 96689 122 ttyp0 00:00:00 pthread 96689 966892 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) PIDLWP NLWP TTYTIME COMMAND 73718 156 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:[EMAIL PROTECTED] ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: -lthr vs. -pthread
libpthread default is M:N threading model, kernel thread entity is allocated on demand, things like sleep() only block thread in userland, no kernel thread will be allocated, so in your example, you won't see 5 kernel threads, only two threads are showed here, the extra thread is a signal thread, there is only one signal thread in process live cycle. libthr is 1:1, when you allocate a thread in userland, it creates a kernel thread too. David Xu Cyrille Lefevre wrote: 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 pthread.h #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) PIDLWP NLWP TTYTIME COMMAND 85146 156 ttyp0 00:00:00 thread 85146 146 ttyp0 00:00:00 thread 85146 136 ttyp0 00:00:00 thread 85146 126 ttyp0 00:00:00 thread 85146 116 ttyp0 00:00:00 thread 85146 851466 ttyp0 00:00:00 thread # ./pthread sleep 1; ps -H -O lwp,nlwp -qC thread (pthread, using -H) PIDLWP NLWP TTYTIME COMMAND 96689 122 ttyp0 00:00:00 pthread 96689 966892 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) PIDLWP NLWP TTYTIME COMMAND 73718 156 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. ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]