From owner-freebsd-threads@FreeBSD.ORG Thu Feb 10 14:25:43 2005 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D288616A4CF; Thu, 10 Feb 2005 14:25:43 +0000 (GMT) Received: from mail.emict.com (brig.emict.com [212.90.172.42]) by mx1.FreeBSD.org (Postfix) with ESMTP id 696C643D48; Thu, 10 Feb 2005 14:25:42 +0000 (GMT) (envelope-from andrit@ukr.net) Received: from [10.0.0.232] (unknown [10.0.0.232]) by mail.emict.com (Postfix) with ESMTP id 6EFD726926; Thu, 10 Feb 2005 16:04:27 +0200 (EET) From: Andriy Tkachuk Organization: eMICT To: freebsd-hackers@freebsd.org User-Agent: KMail/1.7 References: <200502101055.04949.ant@emict.com> <346a8022050210054670390298@mail.gmail.com> In-Reply-To: <346a8022050210054670390298@mail.gmail.com> MIME-Version: 1.0 Content-Disposition: inline Date: Thu, 10 Feb 2005 16:04:27 +0200 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <200502101604.27196.andrit@ukr.net> cc: freebsd-threads@freebsd.org Subject: Re: pthreads & dynamic memory in fbsd vs. the same in linux X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Feb 2005 14:25:44 -0000 i sent the mail with attachement. anyway, the code: (probably the better list would be -threads. sorry folks for flame. i subscribed today to -threads, so please reply to it if no mind.) > cat test2.cc #include #include #include #include #include using std::string; #define COUNT_THREADS 500 pthread_t thread[COUNT_THREADS]; char mode; int iters; void f() { struct timeval t1,t2; void* p[iters]; string s; sleep(2); while (1) { gettimeofday(&t1, NULL); if (mode == 's') { s = ""; for (int i=0; i On Thursday 10 February 2005 15:46, Coleman Kane wrote: > Could you post the code too, perchance? > > On Thu, 10 Feb 2005 10:55:04 +0200, Andriy Tkachuk wrote: > > Hi folks. > > > > I noticed the strange stick of pthreads (amount ~ 500) > > when allocating dynamic memory by malloc or new > > > > in my system: > > > uname -a > > > > FreeBSD ant.emict.com 5.3-STABLE FreeBSD 5.3-STABLE #0: Wed Feb 9 > > 17:30:11 EET 2005 ant@ant:/lin/fbsd_obj/usr/src/sys/ANT i386 > > > > It's interesting that the same program behaves differently > > when it is compiled in linux and run on my fbsd machine in > > linux_base-7.1_7 . > > > > > ldd test2-linux > > > > test2-linux: > > libpthread.so.0 => /lib/libpthread.so.0 (0x28065000) > > libstdc++-libc6.2-2.so.3 => /usr/lib/libstdc++-libc6.2-2.so.3 > > (0x2807c000) libm.so.6 => /lib/libm.so.6 (0x280bf000) > > libc.so.6 => /lib/libc.so.6 (0x280e1000) > > /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x2804c000) > > > > > ldd a.out > > > > a.out: > > libpthread.so.1 => /usr/lib/libpthread.so.1 (0x28075000) > > libstdc++.so.4 => /usr/lib/libstdc++.so.4 (0x28099000) > > libm.so.3 => /lib/libm.so.3 (0x2816b000) > > libc.so.5 => /lib/libc.so.5 (0x28184000) > > > > Each thread allocates the amount of memory by 10 bytes in loop. > > The number of iterations is specified in cmdline arg. The program > > prints the time each thread is spent allocating memory in loop. > > Let's look on results. > > > > > ./a.out n 1000 # 1000 iterations of new operator. Every new allocates > > > 10bytes. > > > > thread 0 created > > thread 1 created > > thread 2 created > > thread 3 created > > thread 4 created > > ... > > thread 497 created > > thread 498 created > > thread 499 created > > 0.001114 > > 0.001022 > > 0.001021 > > 0.001011 > > 0.001014 > > 0.001010 > > 0.001013 > > 0.001050 > > 0.001035 > > 0.001011 > > 0.001013 > > 0.001010 > > 0.001013 > > 0.001010 > > 0.001029 > > 0.001075 > > 0.001053 > > 0.001011 > > 0.001014 > > 0.001011 > > 0.001030 > > 0.001010 > > 0.001015 > > 0.001042 > > 0.001019 > > 0.001011 > > 0.001014 > > 0.001012 > > 0.001013 > > 0.001010 > > 0.001014 > > 0.361604 > > 3.225090 > > 3.225458 > > 3.225696 > > 3.225925 > > 3.226152 > > 3.226380 > > 3.226608 > > 3.226833 > > 3.227062 > > 3.227290 > > 3.227517 > > 3.227744 > > 3.227972 > > 3.228202 > > 3.228451 > > 3.228681 > > 3.228912 > > 3.229140 > > 3.229367 > > > > The same, but in linux_base-7.1_7 : > > > ./test2-linux n 1000 > > > > thread 0 created > > thread 1 created > > ... > > thread 498 created > > thread 499 created > > 0.000467 > > 0.000403 > > 0.000402 > > ... > > 0.000391 > > 0.000391 > > 0.000395 > > ... > > 0.000395 > > 0.010564 > > 0.000398 > > 0.000394 > > > > The program source is attached. > > > > In linux program is compiled by > > $ gcc -v > > Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs > > gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-98) > > > > in fbsd: > > > gcc -v > > > > Using built-in specs. > > Configured with: FreeBSD/i386 system compiler > > Thread model: posix > > gcc version 3.4.2 [FreeBSD] 20040728 > > > > > > _______________________________________________ > > freebsd-hackers@freebsd.org mailing list > > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > > To unsubscribe, send any mail to > > "freebsd-hackers-unsubscribe@freebsd.org" > > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"