뭐가 문제일까요? 도대체.. new 때 에러나는건.?

해봐의 이미지

gdb로 본 backtrace는 담과 같습니다

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1100004288 (LWP 2613)]
0x42074032 in _int_malloc () from /lib/tls/libc.so.6
(gdb) backtrace
#0 0x42074032 in _int_malloc () from /lib/tls/libc.so.6
#1 0x4207335b in malloc () from /lib/tls/libc.so.6
#2 0x400b9e9e in operator new(unsigned) () from /usr/lib/libstdc++.so.5
#3 0x08049a4b in Mutex::create(int) ()
#4 0x0804d18c in CacheEntry::CacheEntry(char const*, unsigned) ()
#5 0x0804d544 in Cache::get_entry(char const*) ()
#6 0x0804c86a in HttpSockHandler::run() ()
#7 0x0804aa16 in PooledExecutor::WorkerThread::do_work(void*) ()
#8 0x400252b6 in start_thread () from /lib/tls/libpthread.so.0

=_=;; 왜 이럴까요..
참 이상함..

Quote:

/*==========================================================================
mutex.hpp 구현부
============================================================================*/

#include "mutex.hpp"
#include "logger.hpp"

#include <pthread.h>
#include <errno.h>

/**
* mutex type 상수 셋팅.
*/
const int Mutex::TYPE_NORMAL = PTHREAD_MUTEX_FAST_NP ;
const int Mutex::TYPE_RECURSIVE = PTHREAD_MUTEX_RECURSIVE_NP;
const int Mutex::TYPE_ERRORCHECK = PTHREAD_MUTEX_ERRORCHECK_NP;

/**
* 해당 type의 mutex를 만든다.
*/
Mutex::Mutex(int type) throw (int)
{
TRACE2("making mutex %d", type);
int ret;

/**
* pthread_mutex attribute
*/
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
TRACE1("3");

ret = pthread_mutexattr_settype(&attr, type);
TRACE1("3");
if( ret != 0 )
throw ret;

TRACE1("3");
this->m_pmutex = new pthread_mutex_t();

TRACE1("3");
ret = pthread_mutex_init((pthread_mutex_t*)this->m_pmutex, &attr);
if( ret != 0 )
throw ret;
TRACE1("3");

pthread_mutexattr_destroy(&attr);
}

/**
* destructor
*/
Mutex::~Mutex()
{
delete (pthread_mutex_t*)this->m_pmutex;
}

/**
* mutex의 factory method. 해당 type의 mutex 생성
*/
Mutex* Mutex::create(int type) throw (int)
{
TRACE1("4");
return new Mutex(type);
}

/**
* 이 object에서 관리하는 mutex를 destroy 시킨다.
*/
void Mutex::destroy() throw (int)
{
//mutex 파괴
int ret = pthread_mutex_destroy((pthread_mutex_t*)this->m_pmutex);
if( ret < 0 )
throw ret;
}

/**
* 이 function을 call 하는 thread가 mutex를 얻는다.
* mutex를 얻을 때까지 block 된다.
* 에러발생시 해당 에러가 throw 된다.
*/
void Mutex::acquire() throw (int)
{
//mutex locking
int ret = pthread_mutex_lock((pthread_mutex_t*)this->m_pmutex);
if(ret < 0)
throw ret;
}

/**
* 이 function을 call 하는 thread가 mutex를 얻고 true를 리턴한다.
* mutex를 얻을 수 없으면 바로 false를 리턴한다.
* 에러발생시 해당 에러가 throw 된다.
*/
bool Mutex::try_acquire() throw (int)
{
int ret = pthread_mutex_trylock((pthread_mutex_t*)this->m_pmutex);
if(ret == EBUSY)
return false;
else if( ret < 0 )
throw ret;
else
return true;
}

/**
* 이 function을 call 하는 thread가 mutex를 반환한다..
* 에러발생시 해당 에러가 throw 된다.
*/
void Mutex::release() throw (int)
{
//mutex unlocking
int ret = pthread_mutex_unlock((pthread_mutex_t*)this->m_pmutex);
if(ret < 0)
throw ret;
}

/**
* 조건변수 생성. 하나의 mutex에 대해 다수의 조건변수 생성 가능.
*/
Condition* Mutex::new_condition()
{
return new Condition(this);
}

/**
* constructor
*/
Condition::Condition(Mutex* mutex)
{
// mutex에 대한 pointer는 Mutex 내부의 메모리 공간사용.
// 반드시 조건변수는 Mutex 와 같이 사용되며 같이 존재하여야 함.
this->m_pmutex = mutex->m_pmutex;

// cond_var 생성. Linux에서는 별다른 attr을 제공하지 않는다.
this->m_pcond = new pthread_cond_t;
int pthread_cond_init_ret = pthread_cond_init((pthread_cond_t*)this->m_pcond, NULL);
if( pthread_cond_init_ret != 0 )
throw pthread_cond_init_ret;
}

/**
* destructor
*/
Condition::~Condition()
{
delete (pthread_cond_t*)this->m_pcond;
}

/**
* 이 조건변수에 대기하고 있는 하나의 thread를 깨운다.
* 아무 thread도 대기하고 있지 않다면 아무 일도 안일어남.
*/
void Condition::signal()
{
int pthread_cond_signal_ret = pthread_cond_signal((pthread_cond_t*)this->m_pcond);
if( pthread_cond_signal_ret != 0 )
throw pthread_cond_signal_ret;
}

/**
* 이 조건변수에 대기하고 있는 모든 thread를 깨운다.
* 아무 thread도 대기하고 있지 않다면 아무 일도 안일어남.
*/
void Condition::signal_all()
{
int pthread_cond_broadcast_ret = pthread_cond_broadcast((pthread_cond_t*)this->m_pcond);
if( pthread_cond_broadcast_ret != 0 )
throw pthread_cond_broadcast_ret;
}

/**
* 이 조건 변수가 trigger 될때까지 무한히 기다린다.
*/
void Condition::await()
{
int pthread_cond_wait_ret = pthread_cond_wait((pthread_cond_t*)this->m_pcond, (pthread_mutex_t*)this->m_pmutex);
if( pthread_cond_wait_ret != 0 )
throw pthread_cond_wait_ret;
}

/**
*이 조건변수를 삭제한다.
*/
void Condition::destroy()
{
int ret = pthread_cond_destroy((pthread_cond_t*)this->m_pcond);
if( ret < 0 )
throw ret;
}

Quote:

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.