当前位置: 首页>>代码示例>>C++>>正文


C++ Shared::Join方法代码示例

本文整理汇总了C++中Shared::Join方法的典型用法代码示例。如果您正苦于以下问题:C++ Shared::Join方法的具体用法?C++ Shared::Join怎么用?C++ Shared::Join使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Shared的用法示例。


在下文中一共展示了Shared::Join方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main


//.........这里部分代码省略.........
         default:
            break;
        }
    }
	PL_DestroyOptState(opt);

    if (help) return -1;

	if (PR_TRUE == debug_mode)
	{
		debug_out = PR_STDOUT;
		PR_fprintf(debug_out, "Test parameters\n");
		PR_fprintf(debug_out, "\tThreads involved: %d\n", thread_limit);
		PR_fprintf(debug_out, "\tIteration limit: %d\n", loop_limit);
		PR_fprintf(debug_out, "\tConcurrency: %d\n", concurrency);
		PR_fprintf(
			debug_out, "\tThread type: %s\n",
			(PR_GLOBAL_THREAD == thread_scope) ? "GLOBAL" : "LOCAL");
	}

    /*
    ** The interesting part starts here
    */
    RCLock lock;
    Shared* shared;
    Home home(NULL, &lock);
    Home* link = &home;
    RCInterval timein, timeout = 0;

    /* Build up the string of objects */
    for (thread_count = 1; thread_count <= thread_limit; ++thread_count)
    {
        shared = new Shared(thread_scope, link, &lock);
        shared->Start();  /* make it run */
        link = (Home*)shared;
	}

    /* Pass the message around the horn a few times */
    for (loop_count = 1; loop_count <= loop_limit; ++loop_count)
    {
		timein.SetToNow();
		for (inner_count = 0; inner_count < INNER_LOOPS; ++inner_count)
		{
			RCEnter entry(&lock);
			home.twiddle = PR_TRUE;
			shared->twiddle = PR_FALSE;
			shared->Notify();
			while (home.twiddle)
            {
				failed = (PR_FAILURE == home.Wait()) ? PR_TRUE : PR_FALSE;
            }
		}
		timeout += (RCInterval(RCInterval::now) - timein);
	}

    /* Figure out how well we did */
	if (debug_mode)
	{
		average = timeout.ToMicroseconds()
			/ (INNER_LOOPS * loop_limit * thread_count);
		PR_fprintf(
			debug_out, "Average switch times %d usecs for %d threads\n",
            average, thread_limit);
	}

    /* Start reclamation process */
    link = shared;
    for (thread_count = 1; thread_count <= thread_limit; ++thread_count)
    {
        if (&home == link) break;
        status = ((Shared*)link)->Interrupt();
		if (PR_SUCCESS != status)
        {
            failed = PR_TRUE;
            if (debug_mode)
			    PL_FPrintError(debug_out, "Failed to interrupt");
        }
		link = link->next; 
    }

    for (thread_count = 1; thread_count <= thread_limit; ++thread_count)
    {
        link = shared->next;
        status = shared->Join();
		if (PR_SUCCESS != status)
		{
            failed = PR_TRUE;
            if (debug_mode)
			    PL_FPrintError(debug_out, "Failed to join");
        }
        if (&home == link) break;
        shared = (Shared*)link;
    }

    PR_fprintf(PR_STDOUT, ((failed) ? "FAILED\n" : "PASSED\n"));

    failed |= (PR_SUCCESS == RCPrimordialThread::Cleanup());

    return ((failed) ? 1 : 0);
}  /* main */
开发者ID:AbrahamJewowich,项目名称:FreeSWITCH,代码行数:101,代码来源:switch.cpp


注:本文中的Shared::Join方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。