Index: /trunk/include/cf_debug.h
===================================================================
--- /trunk/include/cf_debug.h	(revision 61)
+++ /trunk/include/cf_debug.h	(revision 62)
@@ -55,9 +55,25 @@
 
 /**
+ * 디버깅 모듈 초기화
+ *
+ * @see CF_Debug_Initialize
+ */
+# define CF_DEBUG_INITIALIZE										\
+	CF_Debug_Initialize ()
+
+/**
+ * 디버깅 모듈 해제
+ *
+ * @see CF_Debug_Finalize
+ */
+# define CF_DEBUG_FINALIZE											\
+	CF_Debug_Finalize ()
+
+/**
  * 함수에 진입
  *
  * @see CF_Debug_EnterFunction
  */
-# define CF_DEBUG_BEGIN_FUNCTION								\
+# define CF_DEBUG_BEGIN_FUNCTION									\
 	CF_Debug_EnterFunction (__FILE__,__func__,__LINE__)
 
@@ -67,5 +83,5 @@
  * @see CF_Debug_LeaveFunction
  */
-# define CF_DEBUG_END_FUNCTION					\
+# define CF_DEBUG_END_FUNCTION										\
 	CF_Debug_LeaveFunction ()
 
@@ -73,4 +89,6 @@
 # define CF_DEBUG_PRINT(__fp,__fmt,...)
 # define CF_DEBUG_PRINT_BIN(__fp,__bin,__len,__fmt,...)
+# define CF_DEBUG_INITIALIZE
+# define CF_DEBUG_FINALIZE
 # define CF_DEBUG_BEGIN_FUNCTION
 # define CF_DEBUG_END_FUNCTION
@@ -98,4 +116,10 @@
 
 CF_EXPORT int
+CF_Debug_Initialize		(void);
+
+CF_EXPORT int
+CF_Debug_Finalize		(void);
+
+CF_EXPORT int
 CF_Debug_PrintCallStack	(FILE * fp);
 
Index: /trunk/src/cf_debug.c
===================================================================
--- /trunk/src/cf_debug.c	(revision 61)
+++ /trunk/src/cf_debug.c	(revision 62)
@@ -26,9 +26,4 @@
 		return CF_ERROR_DEBUG_INVALID_CTX
 
-#define GET_CTX_OSTREAM(__ctx)				\
-	((((CF_DEBUG_CTX *)__ctx)->fp == NULL)	\
-	 ? stderr								\
-	 : ((CF_DEBUG_CTX *)__ctx)->fp)
-
 /**
  * 디버그 컨텍스트
@@ -66,5 +61,4 @@
 	int			line;
 
-	FILE		* fp;
 	CF_Mutex	mutex;
 
@@ -135,76 +129,4 @@
 		}
 		fprintf (fp, "\n");
-	}
-
-	return CF_OK;
-}
-
-/**
- * 디버그 컨텍스트를 해제
- *
- * @return 성공 시, CF_OK; 실패 시, 오류 코드
- *
- * @param ctx 디버그 컨텍스트
- *
- * @see CF_DEBUG_DESTROY_CTX
- */
-static int
-CF_Debug_DestroyCtx (CF_Debug_Ctx ctx)
-{
-	CF_DEBUG_CTX		* context = (CF_DEBUG_CTX *) ctx;
-	CF_DEBUG_CALLSTACK	* pop = NULL;
-	CF_DEBUG_CALLSTACK	* next = NULL;
-
-	ASSERT_CTX (ctx);
-
-	if (context->fp != NULL)
-		fclose (context->fp);
-
-	for (pop = next = context->callstack.caller ; pop ; pop = next)
-	{
-		next = next->caller;
-		free (pop);
-	}
-
-	if (context->mutex)
-		CF_Mutex_Destory (&context->mutex);
-
-	free (context);
-
-	return CF_OK;
-}
-
-/**
- * 디버그 컨텍스트를 생성
- *
- * @return 성공 시, CF_Debug_Ctx 형태의 컨텍스트; 실패 시, NULL
- * @see CF_DEBUG_CREATE_CTX
- */
-static int
-CF_Debug_CreateCtx (CF_Debug_Ctx * ctx)
-{
-	int				result = 0;
-	CF_DEBUG_CTX	* context = NULL;
-
-	TRY
-	{
-		context = (CF_DEBUG_CTX *) calloc (sizeof (CF_DEBUG_CTX), 1);
-		if (context == NULL)
-		{
-			result = CF_ERROR_DEBUG_ALLOCATE_CTX;
-			TRY_BREAK;
-		}
-
-		result = CF_Mutex_Create (&context->mutex);
-		if (result < 0)
-		{
-			TRY_BREAK;
-		}
-
-		*ctx = (CF_Debug_Ctx) context;
-	}
-	CATCH_IF (result < 0)
-	{
-		CF_Debug_DestroyCtx (context);
 	}
 
@@ -395,5 +317,102 @@
 
 /**
- * 현재 콜스택을 출력
+ * 디버그 컨텍스트를 해제
+ *
+ * @return 성공 시, CF_OK; 실패 시, 오류 코드
+ *
+ * @param ctx 디버그 컨텍스트
+ *
+ * @see CF_DEBUG_DESTROY_CTX
+ */
+static int
+CF_Debug_DestroyCtx (CF_Debug_Ctx ctx)
+{
+	CF_DEBUG_CTX		* context = (CF_DEBUG_CTX *) ctx;
+
+	ASSERT_CTX (ctx);
+
+	while (context->callstack.caller)
+		CF_Debug_CallStackPop (ctx, NULL);
+
+	if (context->mutex)
+		CF_Mutex_Destory (&context->mutex);
+
+	free (context);
+
+	return CF_OK;
+}
+
+/**
+ * 디버그 컨텍스트를 생성
+ *
+ * @return 성공 시, CF_Debug_Ctx 형태의 컨텍스트; 실패 시, NULL
+ * @see CF_DEBUG_CREATE_CTX
+ */
+static int
+CF_Debug_CreateCtx (CF_Debug_Ctx * ctx)
+{
+	int				result = 0;
+	CF_DEBUG_CTX	* context = NULL;
+
+	TRY
+	{
+		context = (CF_DEBUG_CTX *) calloc (sizeof (CF_DEBUG_CTX), 1);
+		if (context == NULL)
+		{
+			result = CF_ERROR_DEBUG_ALLOCATE_CTX;
+			TRY_BREAK;
+		}
+
+		result = CF_Mutex_Create (&context->mutex);
+		if (result < 0)
+		{
+			TRY_BREAK;
+		}
+
+		*ctx = (CF_Debug_Ctx) context;
+	}
+	CATCH_IF (result < 0)
+	{
+		CF_Debug_DestroyCtx (context);
+	}
+
+	return CF_OK;
+}
+
+/**
+ * 콜스택 매니저 초기화 (글로벌 컨텍스트)
+ *
+ * @return 성공 시, CF_OK; 실패 시, 오류 코드
+ *
+ * @see CF_Debug_Finalize
+ */
+int
+CF_Debug_Initialize (void)
+{
+	int result = 0;
+
+	if (gDebugSingleCtx == NULL)
+	{
+		result = CF_Debug_CreateCtx (&gDebugSingleCtx);
+		if (result != CF_OK)
+			return result;
+	}
+
+	return CF_OK;
+}
+
+/**
+ * 콜스택 매니저 해제 (글로벌 컨텍스트)
+ *
+ * @return 성공 시, CF_OK; 실패 시, 오류 코드
+ */
+int
+CF_Debug_Finalize (void)
+{
+	return CF_Debug_DestroyCtx (gDebugSingleCtx);
+}
+
+/**
+ * 현재 콜스택을 출력 (글로벌 컨텍스트)
  *
  * @return 성공 시, CF_OK; 실패 시, 오류 코드
@@ -427,5 +446,5 @@
 
 /**
- * 함수 진입을 명시
+ * 함수 진입을 명시 (글로벌 컨텍스트)
  *
  * @return 성공 시, CF_OK; 실패 시, 오류 코드
@@ -442,14 +461,7 @@
 						const int	line)
 {
-	int				result = 0;
-	CF_DEBUG_CTX	* ctx = NULL;
-
-	if (gDebugSingleCtx == NULL)
-	{
-		result = CF_Debug_CreateCtx (&gDebugSingleCtx);
-		if (result != CF_OK)
-			return result;
-	}
-	ctx = (CF_DEBUG_CTX *)gDebugSingleCtx;
+	CF_DEBUG_CTX * ctx = (CF_DEBUG_CTX *)gDebugSingleCtx;
+
+	ASSERT_CTX (ctx);
 
 	CF_Mutex_Lock (&ctx->mutex);
@@ -461,5 +473,5 @@
 
 /**
- * 함수 종료를 명시
+ * 함수 종료를 명시 (글로벌 컨텍스트)
  *
  * @return 성공 시, CF_OK; 실패 시, 오류 코드
@@ -472,6 +484,5 @@
 	CF_DEBUG_CTX * ctx = (CF_DEBUG_CTX *)gDebugSingleCtx;
 
-	if (ctx == NULL)
-		return CF_ERROR_DEBUG_INVALID_CTX;
+	ASSERT_CTX (ctx);
 
 	CF_Mutex_Lock (&ctx->mutex);
Index: /trunk/test/debug.c
===================================================================
--- /trunk/test/debug.c	(revision 61)
+++ /trunk/test/debug.c	(revision 62)
@@ -23,4 +23,5 @@
 		"『 절원의 템페스트 OP2 Theme 』\n";
 
+	CF_DEBUG_INITIALIZE;
 	CF_DEBUG_BEGIN_FUNCTION;
 
@@ -32,4 +33,5 @@
 
 	CF_DEBUG_END_FUNCTION;
+	CF_DEBUG_FINALIZE;
 
 	return 0;
Index: /trunk/test/test.c
===================================================================
--- /trunk/test/test.c	(revision 61)
+++ /trunk/test/test.c	(revision 62)
@@ -114,4 +114,6 @@
 		if (CF_Thread_Join (&tid[i]) < 0)
 			CF_DEBUG_PRINT (stderr, "failed to join %dth thread\n", i);
+		if (CF_Thread_Release (&tid[i]) < 0)
+			CF_DEBUG_PRINT (stderr, "failed to release %dth thread\n", i);
 	}
 
@@ -255,5 +257,6 @@
 void test_socket (void)
 {
-	CF_Thread tid[THREAD_POOL];
+	CF_Thread stid[THREAD_POOL];
+	CF_Thread ctid[THREAD_POOL];
 
 	int sock = 0;
@@ -289,5 +292,5 @@
 	for (iter = 0 ; iter < THREAD_POOL ; iter++)
 	{
-		if (CF_Thread_Create (&tid[iter], socket_echo_server, &sock) < 0)
+		if (CF_Thread_Create (&stid[iter], socket_echo_server, &sock) < 0)
 		{
 			CF_DEBUG_PRINT (stderr, "failed to create %dth thread\n", iter);
@@ -299,6 +302,5 @@
 	for (iter = 0 ; iter < THREAD_POOL ; iter++)
 	{
-		CF_Thread dummy;
-		if (CF_Thread_Create (&dummy, socket_echo_client, &sock) < 0)
+		if (CF_Thread_Create (&ctid[iter], socket_echo_client, &sock) < 0)
 		{
 			CF_DEBUG_PRINT (stderr, "failed to create %dth thread\n", iter);
@@ -310,6 +312,10 @@
 	for (iter = 0 ; iter < THREAD_POOL ; iter++)
 	{
-		CF_Thread_Join (&tid[iter]);
-		CF_Thread_Release (&tid[iter]);
+		CF_Thread_Join (&ctid[iter]);
+		CF_Thread_Release (&ctid[iter]);
+
+		CF_Thread_Join (&stid[iter]);
+		CF_Thread_Release (&stid[iter]);
+
 		CF_Log_Write (LOG_SOCKET, "SOCKET", "join server thread-%d\n", iter);
 	}
@@ -327,4 +333,5 @@
 int main (int argc, char ** argv)
 {
+	CF_DEBUG_INITIALIZE;
 	CF_DEBUG_BEGIN_FUNCTION;
 
@@ -348,4 +355,5 @@
 
 	CF_DEBUG_END_FUNCTION;
+	CF_DEBUG_FINALIZE;
 
 	return 0;
