Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 7 Apr 2001 10:24:29 +0200
From:      German Tischler <tanis@gaspode.franken.de>
To:        "Brian M. King" <raider1@rochester.rr.com>
Cc:        freebsd-questions@FreeBSD.ORG
Subject:   Re: C++
Message-ID:  <20010407102429.A611@gaspode.franken.de>
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
References:  <000b01c0bf22$14f70460$0d6e1842@King.rochester.rr.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010407102429.A611>