뭐가 문제일까요? 도대체.. 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
=_=;; 왜 이럴까요..
참 이상함..
/*==========================================================================
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;
}
댓글 달기