int main( int argc, char **argv )
{
    // google::InitGoogleLogging(argv[0]);

    LOG(INFO) << "main thread " << THIS_THREAD_ID << " running...";

    // 如果没有,io_service 执行完了队列中所有缓存的job就退出,在getchar()之前terminating
    boost::asio::io_service::work io_work( std::ref(g_io_service) );

    boost::thread_group thrgrp;

    for (int i = 0; i < 5; ++i)
        thrgrp.create_thread( run_io_service );

    SLEEP_SECONDS(1);

    g_io_service.dispatch( std::bind(job_func, 1) );

    getchar();
    LOG(INFO) << "Trying to stop io_service...";

    // NOTE!!! 如果job_func里用dispatch就停不下来,嵌套
    g_io_service.stop();

    thrgrp.join_all();

    return 0;
}
Exemplo n.º 2
0
void* Msclient(void*)
{
	TIniFile tf;
	char tmp[256];	

    if (!tf.Open(INI_FILE_NAME))
    {
        printf("can not find\n");
        exit(-1000);
    }

    int marketnum = tf.ReadInt("COMMON","MARKETDATANUM",1);
	int i = 0;

	for(;i<marketnum;i++)
	{
		sprintf(tmp,"MARKETDATA%d",i+1);
		CUstpMs ustpMs;
        ustpMs.InitInstance(tmp,INI_FILE_NAME,&tradepanel);
	}
    while(false)
	{
		SLEEP_SECONDS(5000);
	}
    return 0;
}
/*
 * NOTE!!! post dispatch 区别仅仅在io_service调用的工作函数里使用才看得出区别。
 * dispatch 只有start没有finish
 */
static
void job_func(int i)
{
    LOG(INFO) << "Job " << i << " started in thread " << THIS_THREAD_ID;
    SLEEP_SECONDS(2);
    // g_io_service.dispatch(std::bind(job_func, i+1));
    g_io_service.post(std::bind(job_func, i+1));
    LOG(INFO) << "Job " << i << " finished in thread " << THIS_THREAD_ID;
}
int main()
{
    printf("\rHello, world!");
    fflush(stdout);

    SLEEP_SECONDS(1);

    printf("\r                                                                                                ");
    fflush(stdout);
    printf("\rCharles");
    fflush(stdout);

    getchar();
    putchar('\n');

    return 0;
}
Exemplo n.º 5
0
int main()
{
	TIniFile tf;
	char tmp[256];	
	if (!tf.Open(INI_FILE_NAME))
	{
		printf("不能打开配置文件\n");
		exit(-1000);
	}
	int marketnum = tf.ReadInt("COMMON","MARKETDATANUM",1);
	int i = 0;
	for(;i<marketnum;i++)
	{
		sprintf(tmp,"MARKETDATA%d",i+1);
		CUstpMs ustpMs;
		ustpMs.InitInstance(tmp,INI_FILE_NAME);
	}
	while(true)
	{
		SLEEP_SECONDS(5000);
	}
	return 0;
}