コード例 #1
0
int main(int argc, char **argv)
{
	PRThread *r, *w;


	PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
    PR_STDIO_INIT();

    emptyBufs = PR_NewSem(2);	/* two empty buffers */

    fullBufs = PR_NewSem(0);	/* zero full buffers */

	/* Create initial temp file setup */
	InitialSetup();
	
	/* create the reader thread */
	
	r = PR_CreateThread(PR_USER_THREAD,
				      reader, t1, 
				      PR_PRIORITY_NORMAL,
				      PR_LOCAL_THREAD,
    				  PR_JOINABLE_THREAD,
				      0);

	w = PR_CreateThread(PR_USER_THREAD,
				      writer, t2, 
				      PR_PRIORITY_NORMAL,
                      PR_LOCAL_THREAD,
                      PR_JOINABLE_THREAD,
                      0);

    /* Do the joining for both threads */
    (void) PR_JoinThread(r);
    (void) PR_JoinThread(w);

    /* Do the verification and clean up */
    VerifyAndCleanup();

    PR_DestroySem(emptyBufs);
    PR_DestroySem(fullBufs);

    PR_Cleanup();

    if(failed_already)
    {
        printf("Fail\n");
        return 1;
    }
    else
    {
        printf("PASS\n");
        return 0;
    }


}
コード例 #2
0
int main(int argc, char **argv)
{
	PRThread *r;

    PR_STDIO_INIT();
    PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);

    {
    	/* The command line argument: -d is used to determine if the test is being run
    	in debug mode. The regress tool requires only one line output:PASS or FAIL.
    	All of the printfs associated with this test has been handled with a if (debug_mode)
    	test.
    	Usage: test_name -d
    	*/
    	PLOptStatus os;
    	PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
    	while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
        {
    		if (PL_OPT_BAD == os) continue;
            switch (opt->option)
            {
            case 'd':  /* debug mode */
    			debug_mode = 1;
                break;
             default:
                break;
            }
        }
    	PL_DestroyOptState(opt);
    }        

 /* main test */

#ifdef XP_MAC
	SetupMacPrintfLog("sem.log");
	debug_mode = 1;
#endif

    emptyBufs = PR_NewSem(2);	/* two empty buffers */

    fullBufs = PR_NewSem(0);	/* zero full buffers */

	/* create the reader thread */
	
	r = PR_CreateThread(PR_USER_THREAD,
				      reader, 0, 
				      PR_PRIORITY_NORMAL,
				      PR_LOCAL_THREAD,
    				  PR_UNJOINABLE_THREAD,
				      0);

	/* Do the writer operation in this thread */
	writer();

	PR_DestroySem(emptyBufs);
	PR_DestroySem(fullBufs);

	if (finalResult == PR_SUCCESS) {
		if (debug_mode) printf("sem Test Passed.\n");
	}
	else{
		if (debug_mode) printf("sem Test Failed.\n");
		failed_already=1;
	}
    PR_Cleanup();
	if(failed_already)	
		return 1;
	else
		return 0;
}