77777

 
int main()  
{  
    ReadInitConfig("config.xml");  
  
    CURLcode res; //定义CURLcode类型的变量  
    pthread_t threads[1000];//PID  
    int i, ret;  
    struct HttpGetParam httpGetParams[1000];  
    pthread_attr_t thread_attr;
    size_t stack_size;
	void *thrd_ret;
	
	QueryPerformanceFrequency(&m_nFreq); // 获取时钟周期

    m_PacketUseTime.clear();  
	
    res = curl_global_init(CURL_GLOBAL_ALL);  
    if (res != CURLE_OK)  
    {  
        printf( "Failed to global init default [%d]\n", res );  
        return 1;  
    }   
      
    memset(threads, 0, sizeof(threads));  
    memset(httpGetParams, 0, sizeof(httpGetParams));  
      
    for ( i = 0; i < configvalues.MaxThread; i++)  
    {  
        //目标URL  
        //httpGetParams[i].url = "http://127.0.0.1";  
        httpGetParams[i].url = configvalues.DefaultUrl;  
    }  

    pthread_mutex_init(&mutex, NULL);        //初始化线程锁  
  
    //printf("PTHREAD_STACK_MIN=%d\r\n", PTHREAD_STACK_MIN);    
  
    pthread_attr_init(&thread_attr);  
    pthread_attr_getstacksize(&thread_attr, &stack_size);  
      
    pthread_attr_setstacksize(&thread_attr, 1024 * 1024);  
    pthread_attr_getstacksize(&thread_attr, &stack_size);    
      
    //printf("New stack size is %u; minimum is %u\n", stack_size, PTHREAD_STACK_MIN);  

    for ( i = 0; i < configvalues.MaxThread; i++)  
    {  
        ret = pthread_create(&threads[i], &thread_attr, http_get, (void *)&httpGetParams[i]);  
        if (0 != ret)  
        {  
            perror("pthread_create failed!!! The reason is:");    
        }  
    }  
    pthread_attr_destroy(&thread_attr);    

    Sleep(2);
    for ( i = 0; i <configvalues.MaxThread ; i++)  
    {  
        if (&threads[i] != 0)  
        {  
            pthread_cancel(threads[i]);  
            pthread_join(threads[i], &thrd_ret);  
        }  
    }  

    pthread_mutex_destroy(&mutex);  
  
    printf("SendPaket ------- %d\r\n", configvalues.MaxThread);  
    printf("Success --------- %d\r\n", RecNum);  
    if(!m_PacketUseTime.empty())  
    {  
        printf("MaxUesTime ------ %f\r\n", *max_element(m_PacketUseTime.begin(), m_PacketUseTime.end()));  
        printf("MinUesTime ------ %f\r\n", *min_element(m_PacketUseTime.begin(), m_PacketUseTime.end()));  
        printf("AverageTime ----- %f\r\n", accumulate(m_PacketUseTime.begin(), m_PacketUseTime.end(), 0)/(double)m_PacketUseTime.size());  
    }  
    else  
    {  
        printf("there is not have any data in rong qi!!\r\n");   
    }

	system("pause");
    return 0;  
}  

你可能感兴趣的:(JOIN,thread,struct,null,url,System)