Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 29 Aug 2001 16:54:02 +0400
From:      "Igor Tchernov" <tchernov@pobox.spbu.ru>
To:        <questions@FreeBSD.org>
Subject:   operators new/delete with pthreads
Message-ID:  <001901c13089$c0a24f80$0200a8c0@tchermob>

next in thread | raw e-mail | index | archive | help
Dear people,
Although you don't like to answer questions like "why my programm doesn't
work?", I've no way more to find why the error appears at the using
new/delete operators with the pthreads. I've represented this error in small
programm below. After few seconds running breaks this programm down with the
"Segmentation fault" or "Bus error". This error appears in the FreeBSD but
in the OpenBSD works this properly. What the reason?

-----------------------------------
// test_new_delete.cpp : test new/delete operators in multithreading.
// g++ -pthread test_new_delete.cpp

#include <stdio.h>
#include <pthread.h>

class CTestNewDelete
{
public:
 char *pData;
 CTestNewDelete();
 ~CTestNewDelete();
};

CTestNewDelete::CTestNewDelete()
{
 pData = new char[10];
}

CTestNewDelete::~CTestNewDelete()
{
 delete [] pData;
}

static void ThreadFunc_1()
{
 CTestNewDelete data;
}

static void ThreadFunc_2()
{
 CTestNewDelete data;
}

static void* Thread_1(void *)
{
 while(true)
  ThreadFunc_1();
 return NULL;
}

static void* Thread_2(void *)
{
 while(true)
  ThreadFunc_2();
 return NULL;
}

int main(int argc, char* argv[])
{
 pthread_t thread1 = 0, thread2 = 0;

 if (pthread_create(&thread1, NULL, Thread_1, NULL) != 0)
 {
  printf("start Thread_1 failed");
  exit(1);
 }

 if (pthread_create(&thread2, NULL, Thread_2, NULL) != 0)
 {
  printf("start Thread_2 failed");
  exit(1);
 }

 while (true);

 return 0;
}
-----------------------------------

System:
FreeBSD tcherdom 4.2-RELEASE FreeBSD 4.2-RELEASE #8: Sun Jan 21 17:05:56 MSK
200
1     root@tcherdom:/usr/src/sys/compile/TCHERDOM  i386
Package:
pth-1.3.7           GNU Portable Threads

best regards, Igor Tchernov.





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?001901c13089$c0a24f80$0200a8c0>