Date: Thu, 3 Mar 2005 13:00:12 +0530 From: "Andriy Tkachuk" <andrit@ukr.net> To: <threads@freebsd.org> Subject: Re: patch for threads/76690 - critical - fork hang in child for-lc_r Message-ID: <005201c51fc2$d8676b60$090210ac@BORJA> References: <Pine.GSO.4.43.0503021042310.26125-100000@sea.ntplx.net> <000b01c51fbb$4189ea30$090210ac@BORJA>
next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format. ------=_NextPart_000_004F_01C51FF0.EF8D15A0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit But if one wants to use pure user threads on his UP system, what he will chose if not libc_r ? And i have some test program with shows the better results for libc_r than for libpthreads. Take a look. The program is the 500 threads, each of them allocate memory in loop and then free it in another loop. Program outputs the time consumed for this two loops. See the results. > ./a.out m 1000 10 # 1000 iterations, malloc by 10 bytes memory chanks thread 0 created thread 1 created thread 2 created thread 3 created ... thread 499 created 0.000870 0.000544 0.000695 0.000594 0.000913 ... (after some time, say 10-20 seconds, there is stable picture: ) 0.001056 0.000756 0.000485 0.000476 0.000528 0.000479 0.000550 0.000481 0.000561 0.000541 0.000483 0.000558 0.000482 0.000561 0.000532 0.000479 0.000551 0.000484 0.000923 0.001180 0.000981 0.000492 0.000996 0.000536 0.000975 0.000534 this is for libc_r. Let's see what about lpthreads. > c++ -lpthread test2.cc > ./a.out m 1000 10 thread 0 created thread 1 created ... thread 498 created thread 499 created 0.001704 0.001707 0.001671 0.001683 0.001691 0.001664 0.001661 0.001683 0.001709 ... 0.001643 0.002018 0.001668 0.001672 0.001744 0.001689 0.001672 0.001682 0.001643 0.001687 0.001670 0.001692 0.001677 0.001732 0.001650 0.001685 0.001678 0.001685 1.303800 5.266314 5.268821 5.268158 5.268539 5.268644 5.268515 5.268963 5.269147 5.268968 5.268928 ... 5.341573 5.341051 5.341417 5.341327 5.341084 5.340510 5.340974 5.340914 5.341118 ... So what? The test2.cc is attached. (of course all was done on current: > uname -a FreeBSD fbsd 6.0-CURRENT FreeBSD 6.0-CURRENT #0: Tue Mar 1 16:03:09 IST 2005 ant@fbsd:/usr/obj/usr/src/sys/FBSD i386 ) > > Is there a reason you are still using libc_r? > > I don't use it at all, but there was critical bug > i threads-pr - so i just decided to fix it since i > have had some time ) > > If this library is needless, why is it still there > and this pr in criticals? ------=_NextPart_000_004F_01C51FF0.EF8D15A0 Content-Type: application/octet-stream; name="test2.cc" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="test2.cc" #include <pthread.h>=0A= #include <stdio.h>=0A= #include <unistd.h>=0A= #include <sys/time.h>=0A= #include <string>=0A= =0A= using std::string;=0A= =0A= #define COUNT_THREADS 500=0A= =0A= pthread_t thread[COUNT_THREADS];=0A= =0A= char mode;=0A= int iters;=0A= int chanksz;=0A= =0A= void f()=0A= {=0A= struct timeval t1,t2;=0A= void* p[iters];=0A= string s;=0A= =0A= sleep(2);=0A= =0A= while (1)=0A= {=0A= =0A= gettimeofday(&t1, NULL);=0A= =0A= if (mode =3D=3D 's') {=0A= s =3D "";=0A= for (int i=3D0; i<iters; i++)=0A= s +=3D 'a';=0A= }=0A= if (mode =3D=3D 'S') {=0A= string s;=0A= for (int i=3D0; i<iters; i++)=0A= s =3D 'a';=0A= }=0A= =0A= if (mode =3D=3D 'f')=0A= for (int i=3D0; i<iters; i++)=0A= gettimeofday(&t2, NULL);=0A= =0A= if (mode =3D=3D 'm') {=0A= for (int i=3D0; i<iters; i++)=0A= p[i] =3D malloc(chanksz);=0A= for (int i=3D0; i<iters; i++)=0A= free(p[i]);=0A= }=0A= if (mode =3D=3D 'n') {=0A= for (int i=3D0; i<iters; i++)=0A= p[i] =3D (char*) new char(chanksz);=0A= for (int i=3D0; i<iters; i++)=0A= delete (char*) p[i];=0A= }=0A= =0A= gettimeofday(&t2, NULL);=0A= =0A= int usec_d =3D t2.tv_usec-t1.tv_usec;=0A= int sec_d =3D t2.tv_sec-t1.tv_sec;=0A= if (usec_d<0) {=0A= sec_d--;=0A= usec_d +=3D 1000000;=0A= }=0A= =0A= printf( "%u.%06u \n", sec_d, usec_d);=0A= }=0A= }=0A= =0A= =0A= int main(int argc, char *argv[])=0A= {=0A= =0A= mode =3D argv[1][0];=0A= iters =3D atoi(argv[2]);=0A= =0A= if (mode =3D=3D 'n' || mode =3D=3D 'm')=0A= chanksz =3D atoi(argv[3]);=0A= =0A= for (int i=3D0; i<COUNT_THREADS; i++) {=0A= pthread_create ( &(thread[i]), NULL, (void*(*)(void*))f, NULL );=0A= printf("thread %i created\n", i);=0A= }=0A= while(1) { sleep(1); }=0A= }=0A= ------=_NextPart_000_004F_01C51FF0.EF8D15A0--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?005201c51fc2$d8676b60$090210ac>