Changeset 49 in libcf


Ignore:
Timestamp:
03/29/13 18:02:55 (11 years ago)
Author:
cheese
Message:

#1 fix test code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/test.c

    r40 r49  
    2424CF_Debug_Ctx        gDebugCtx;
    2525CF_Debug_CallStack  gDebugCallstack;
     26CF_Mutex            globalMutex;
    2627
    2728#define LOG_SOCKET      0
     
    3233CF_THREAD_RETURN CF_THREAD_CALL test_log_mt (void * arg)
    3334{
     35    static int cnt = 0;
    3436    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);
    3648
    3749    for (i = 0 ; i < 100000 ; i++)
     
    3951        CF_Log_Write (LOG_MT, "LOG_MT", "[%d] multi-threadedlogging test %d\n", th, i);
    4052    }
     53
     54    CF_DEBUG_PRINT (stderr, "end %dth thread\n", th);
    4155
    4256    return (CF_THREAD_RETURN)0;
     
    8599        CF_DEBUG_PRINT (stderr, "set multi-threading mode error\n");
    86100
     101    if (CF_Mutex_Create (&globalMutex) < 0) {
     102        // error
     103    }
     104
    87105    for (i = 0 ; i < 10 ; i++)
    88106    {
     
    92110            return ;
    93111        }
    94         CF_DEBUG_PRINT (stderr, "created %dth thread\n", i);
     112    }
     113
     114    if (CF_Mutex_Destory (&globalMutex) < 0) {
     115        // error
    95116    }
    96117
     
    244265    int sock = 0;
    245266    int iter = 0;
    246     int reuse = 1;
    247267
    248268    /*------------------------------------------------------------*/
     
    272292    }
    273293    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");
    281294
    282295    for (iter = 0 ; iter < THREAD_POOL ; iter++)
Note: See TracChangeset for help on using the changeset viewer.