From owner-freebsd-questions Sat Apr 7 1:25:36 2001 Delivered-To: freebsd-questions@freebsd.org Received: from elvis.franken.de (elvis.franken.de [193.175.24.41]) by hub.freebsd.org (Postfix) with ESMTP id 0007D37B422 for ; Sat, 7 Apr 2001 01:25:21 -0700 (PDT) (envelope-from tanis@gaspode.franken.de) Received: from uucp by elvis.franken.de with local-rmail (Exim 3.22 #1) id 14lo24-0007DS-00; Sat, 07 Apr 2001 10:25:20 +0200 Received: from gaspode.franken.de (lengfeld.core.main.franken.de [193.141.110.4]) by karnickel.franken.de (8.11.1/8.11.1) with ESMTP id f378OSV11767; Sat, 7 Apr 2001 10:24:28 +0200 (CEST) (envelope-from tanis@gaspode.franken.de) Received: (from tanis@localhost) by gaspode.franken.de (8.11.2/8.11.1) id f378OTX01027; Sat, 7 Apr 2001 10:24:29 +0200 (CEST) (envelope-from tanis) Date: Sat, 7 Apr 2001 10:24:29 +0200 From: German Tischler To: "Brian M. King" Cc: freebsd-questions@FreeBSD.ORG Subject: Re: C++ Message-ID: <20010407102429.A611@gaspode.franken.de> References: <000b01c0bf22$14f70460$0d6e1842@King.rochester.rr.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-md5; protocol="application/pgp-signature"; boundary="UlVJffcvxoiEqYs2" Content-Disposition: inline User-Agent: Mutt/1.2.5-current-20010403i In-Reply-To: <000b01c0bf22$14f70460$0d6e1842@King.rochester.rr.com>; from raider1@rochester.rr.com on Sat, Apr 07, 2001 at 01:17:46AM -0400 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG --UlVJffcvxoiEqYs2 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Apr 07, 2001 at 01:17:46AM -0400, Brian M. King wrote: > Hello. I am currently in the process of developing an IRCd > in C++ on FreeBSD and while I was creating some test code I discovered > a problem and no programmers that I know seem to have any ideas as to > why its happening. I have the main() opening a socket for listening > and accepting connections. I also have a threaded function (Using > POSIX threads) that reads data from all the sockets and stores it > into an STL Queue system. I then have several work threads running > the same function that reads from the STL Queue list to handle the > data appropriatly. In the first thread that reads from the sockes I > am allocating the memory for each container element using 'char *msg > =3D new char[size]' .. The problem I am having is in the worker threads > that handle the queues I do a 'char *msg; msg =3D MessageQueue.front(); > MessageQueue.pop(); if (msg !=3D NULL) { delete [] msg; }' When it tries > to delete the allocated memory I get the error 'Junk pointer, too > high to make sense.' but I've used this method before without a > problem. I am running FreeBSD 4.2-RELEASE and am compiling with g++ > .. I am attaching the test program I've written to develop the STL > Container system I will need in the ircd itself. >=20 > To compile: g++ -pthread -Wall -g -o sin sin2.cpp The C++ standard does not know anything about threads. This means that the STL is by definition not thread safe. There may be implementations that are, but a non thread-safe STL is perfectly valid. The STL that comes with FreeBSD is apparently not thread-safe at the time being. That means you have to do thread synchronization yourself. (means: use mutexes to lock data structures when they are changed). --gt=20 --UlVJffcvxoiEqYs2 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: PGPfreeware 5.0i for non-commercial use MessageID: ZmvaeTX90bp4NuEOcCqTM9SiCJCXgbgV iQEVAwUBOs7OvL7hO6NLB/FvAQG9ewf/UQgSg6PUUJ0XD3NuGfjQpO9DGSDj/N6R oWkJYNnhDc8uGjYQpr03JWOB1OvNHXDat8arim/2M/Af1ArPOc9LPsyoKoZgO7HA H6K6NICx9V4EOM6sKHC9WzG2ZDOnOeJz75GWlJUQteFFaromYA1xu6YcpIF/6XiM 4VKTNq4Mw3T3GxVBEW8yo379vGG+b5fh/GRLP5i6alS7CsoMItq05AbfIK2r8g/1 EetTfQdUzCKVfTNY+grT7DLTz6ZHuINnQvOYBHUiqHNYbGckt1K4GPDrUCZCU+QD mH4OeZ2GHWJPX/LGHkKeOi+Cs9weT0PYSphquHfyNRYYLp7uQjGwEQ== =o8v8 -----END PGP SIGNATURE----- --UlVJffcvxoiEqYs2-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message