zoukankan      html  css  js  c++  java
  • SRS流媒体服务器03 ---- st-thread

    st-thread下载编译

    srs使用的是st-thread,下面我们来研究一下。

    下载:

      官网:http://sourceforge.net/projects/state-threads/

      git:https://github.com/toffaletti/state-threads

    编译:

    tar zxvf st-1.9.tar.gz 
    cd st-1.9 
    make linux-debug

    然后会得到obj目录。里面有生成的中间文件*.o, 头文件st.h,libst.so,libst.a和example中的几个例子:lookupdns,proxy,server等,这里注意st.h是动态生成的。

    example:

    //gcc -I../obj -g huge_threads.c ../obj/libst.a -o huge_threads
    
    //./huge_threads 10000
    
    //./huge_threads 30000
    
    //
    #include <stdio.h>
    #include "st.h"
    #define SLEEP_INTERVAL 30  //in m
    
    void* do_calc(void* arg){
        long pidx = *(long*)arg;
        for(;;){
            printf("sthread [#%ld] usleep
    ", pidx);
            st_usleep(SLEEP_INTERVAL * 1000);
        }
        return NULL;
    }
    
     
    
    int main(int argc, char** argv){
        if(argc <= 1){
            printf("Test the concurrence of state-threads!
    "
                "Usage: %s <sthread_count>
    "
                "eg. %s 10000
    ", argv[0], argv[0]);
            return -1;
        }
        if(st_init() < 0){
            printf("state threads lib runtime init error!");
            reurn -1;
        }
    
     
    
        int i, count = atoi(argv[1]);
        for(i = 1; i <= count; i++){
            if(st_thread_create(do_calc, (void*)&i, 0, 0) == NULL){
                printf("create state thread %d failed
    ", i);
                return -1;
            }
        }
        st_thread_exit(NULL);
        return 0;
    }

     编译:

    gcc -I../obj -g huge_threads.c ../obj/libst.a  -o huge_threads

    运行

    ./huge_threads 10000

    可以看看程序占用的内存和CPU等。

  • 相关阅读:
    mysql 查询当月天数
    mybatis <collection>标签 类型为string时无法获取重复数据错误
    eclipse 关闭validating
    YAGNI 声明
    tomcat 异常
    svn 用cmd命令行启动服务
    linux 命令
    windows10安装liux系统
    一带一路是个啥?
    串口通信协议
  • 原文地址:https://www.cnblogs.com/vczf/p/13961473.html
Copyright © 2011-2022 走看看