Changeset 49 in libcf for trunk/test/test.c
- Timestamp:
- 03/29/13 18:02:55 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/test.c
r40 r49 24 24 CF_Debug_Ctx gDebugCtx; 25 25 CF_Debug_CallStack gDebugCallstack; 26 CF_Mutex globalMutex; 26 27 27 28 #define LOG_SOCKET 0 … … 32 33 CF_THREAD_RETURN CF_THREAD_CALL test_log_mt (void * arg) 33 34 { 35 static int cnt = 0; 34 36 int i = 0; 35 int th = *((int *)arg); 37 int th = 0; 38 39 if (CF_Mutex_Lock (&globalMutex) < 0) { // for critical section 40 // error 41 } 42 th = cnt++; 43 if (CF_Mutex_Unlock (&globalMutex) < 0) { // for critical section 44 // error 45 } 46 47 CF_DEBUG_PRINT (stderr, "created %dth thread\n", th); 36 48 37 49 for (i = 0 ; i < 100000 ; i++) … … 39 51 CF_Log_Write (LOG_MT, "LOG_MT", "[%d] multi-threadedlogging test %d\n", th, i); 40 52 } 53 54 CF_DEBUG_PRINT (stderr, "end %dth thread\n", th); 41 55 42 56 return (CF_THREAD_RETURN)0; … … 85 99 CF_DEBUG_PRINT (stderr, "set multi-threading mode error\n"); 86 100 101 if (CF_Mutex_Create (&globalMutex) < 0) { 102 // error 103 } 104 87 105 for (i = 0 ; i < 10 ; i++) 88 106 { … … 92 110 return ; 93 111 } 94 CF_DEBUG_PRINT (stderr, "created %dth thread\n", i); 112 } 113 114 if (CF_Mutex_Destory (&globalMutex) < 0) { 115 // error 95 116 } 96 117 … … 244 265 int sock = 0; 245 266 int iter = 0; 246 int reuse = 1;247 267 248 268 /*------------------------------------------------------------*/ … … 272 292 } 273 293 CF_Log_Write (LOG_SOCKET, "SOCKET", "socket ready\n"); 274 275 if (CF_Socket_SetOption (sock, SO_REUSEADDR, &reuse, sizeof (reuse)) < 0)276 {277 CF_DEBUG_PRINT (stderr, "failed to set option\n");278 return ;279 }280 CF_Log_Write (LOG_SOCKET, "SOCKET", "set socket option\n");281 294 282 295 for (iter = 0 ; iter < THREAD_POOL ; iter++)
Note:
See TracChangeset
for help on using the changeset viewer.