nsprpub/pr/tests/short_thread.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/nsprpub/pr/tests/short_thread.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,58 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include <stdio.h>
    1.10 +#include "nspr.h"
    1.11 +#include "plgetopt.h"
    1.12 +
    1.13 +/*
    1.14 + * Create a thread that exits right away; useful for testing race conditions in thread
    1.15 + * creation
    1.16 + */
    1.17 +
    1.18 +int _debug_on = 0;
    1.19 +#define DPRINTF(arg) if (_debug_on) printf arg
    1.20 +
    1.21 +static void housecleaning(void *cur_time);
    1.22 +
    1.23 +int main (int argc, char **argv)
    1.24 +{
    1.25 +	static PRIntervalTime thread_start_time;
    1.26 +	static PRThread *housekeeping_tid = NULL;
    1.27 +	PLOptStatus os;
    1.28 +	PLOptState *opt = PL_CreateOptState(argc, argv, "d");
    1.29 +
    1.30 +	while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
    1.31 +	{
    1.32 +		if (PL_OPT_BAD == os) continue;
    1.33 +		switch (opt->option)
    1.34 +		{
    1.35 +			case 'd':  /* debug mode */
    1.36 +				_debug_on = 1;
    1.37 +				break;
    1.38 +			default:
    1.39 +				break;
    1.40 +		}
    1.41 +	}
    1.42 +	PL_DestroyOptState(opt);
    1.43 +
    1.44 +	if (( housekeeping_tid = 
    1.45 +		PR_CreateThread (PR_USER_THREAD, housecleaning,  (void*)&thread_start_time,
    1.46 +						 PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0)) 
    1.47 +																		== NULL ) {
    1.48 +		fprintf(stderr,
    1.49 +			"simple_test: Error - PR_CreateThread failed: (%ld, %ld)\n",
    1.50 +									  PR_GetError(), PR_GetOSError());
    1.51 +		exit( 1 );
    1.52 +	}
    1.53 +	PR_Cleanup();
    1.54 +	return(0);
    1.55 +}
    1.56 +
    1.57 +static void
    1.58 +housecleaning (void *cur_time) 
    1.59 +{
    1.60 +  DPRINTF(("Child Thread exiting\n"));
    1.61 +}

mercurial