Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 9 Apr 2001 10:55:10 +0100
From:      "Jim Long" <longj@OIT.EDU>
To:        "Brian M. King" <raider1@rochester.rr.com>, <freebsd-questions@FreeBSD.ORG>
Subject:   Re: C++
Message-ID:  <02c201c0c0db$2cc73f00$798dd38c@oit.edu>
References:  <000b01c0bf22$14f70460$0d6e1842@King.rochester.rr.com>

next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.

------=_NextPart_000_02BF_01C0C0E3.8C456080
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Are the your data structures thread safe? Dou you have good thread synch =
built in?
  ----- Original Message -----=20
  From: Brian M. King=20
  To: freebsd-questions@FreeBSD.ORG=20
  Sent: Saturday, April 07, 2001 6:17 AM
  Subject: C++


      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.

  To compile: g++ -pthread -Wall -g -o sin sin2.cpp
  To Run: ./sin

  Open a socket connection to the box this program is running on on port =
1600 and send data to it, you will see the error (Which occurs in the =
queue_handler function).

  -Brian

------=_NextPart_000_02BF_01C0C0E3.8C456080
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4522.1800" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>Are the your data structures thread safe? Dou you =
have good=20
thread synch built in?</FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A title=3Draider1@rochester.rr.com =
href=3D"mailto:raider1@rochester.rr.com">Brian=20
  M. King</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A=20
  title=3Dfreebsd-questions@FreeBSD.ORG=20
  =
href=3D"mailto:freebsd-questions@FreeBSD.ORG">freebsd-questions@FreeBSD.O=
RG</A>=20
  </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Saturday, April 07, 2001 =
6:17=20
  AM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> C++</DIV>
  <DIV><BR></DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; Hello. I am =
currently in the=20
  process of developing an IRCd in C++ on FreeBSD and while I was =
creating some=20
  test code I discovered a problem and no programmers that I know seem =
to have=20
  any ideas as to why its happening. I have the main() opening a socket =
for=20
  listening and accepting connections. I also have a threaded function =
(Using=20
  POSIX threads) that reads data from all the sockets and stores it into =
an STL=20
  Queue system. I then have several work threads running the same =
function that=20
  reads from the STL Queue list to handle the data appropriatly. In the =
first=20
  thread that reads from the sockes I am allocating the memory for each=20
  container element using 'char *msg =3D new char[size]' .. The problem =
I am=20
  having is in the worker threads that handle the queues I do a 'char =
*msg; msg=20
  =3D MessageQueue.front(); MessageQueue.pop(); if (msg !=3D NULL) { =
delete [] msg;=20
  }' When it tries to delete the allocated memory I get the error 'Junk =
pointer,=20
  too high to make sense.' but I've used this method before without a =
problem. I=20
  am running FreeBSD 4.2-RELEASE and am compiling with g++ .. I am =
attaching the=20
  test program I've written to develop the STL Container system I will =
need in=20
  the ircd itself.</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>To compile: g++ -pthread -Wall -g -o =
sin=20
  sin2.cpp</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>To Run: ./sin</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>Open a socket connection to the box =
this program=20
  is running on on port 1600 and send data to it, you will see the error =
(Which=20
  occurs in the queue_handler function).</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial =
size=3D2>-Brian</FONT></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_02BF_01C0C0E3.8C456080--


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?02c201c0c0db$2cc73f00$798dd38c>