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


C++ UNRESOLVED函数代码示例

本文整理汇总了C++中UNRESOLVED函数的典型用法代码示例。如果您正苦于以下问题:C++ UNRESOLVED函数的具体用法?C++ UNRESOLVED怎么用?C++ UNRESOLVED使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: main

/* main function */
int main()
{
	int ret;
	long rts;

	struct sigaction sa;

	/* Initialize output */
	output_init();

	/* Test the RTS extension */
	rts = sysconf(_SC_REALTIME_SIGNALS);

	if (rts < 0L)
	{
		UNTESTED("This test needs the RTS extension");
	}

	/* Set the signal handler */
	sa.sa_flags = SA_SIGINFO;

	sa.sa_sigaction = handler;

	ret = sigemptyset(&sa.sa_mask);

	if (ret != 0)
	{
		UNRESOLVED(ret, "Failed to empty signal set");
	}

	/* Install the signal handler for SIGQUIT */
	ret = sigaction(SIGNAL, &sa, 0);

	if (ret != 0)
	{
		UNRESOLVED(ret, "Failed to set signal handler");
	}

	if (called)
	{
		FAILED("The signal handler has been called when no signal was raised");
	}

	ret = raise(SIGNAL);

	if (ret != 0)
	{
		UNRESOLVED(ret, "Failed to raise SIGQUIT");
	}

	if (!called)
	{
		FAILED("the sa_handler was not called whereas SA_SIGINFO was not set");
	}

	/* Test passed */
#if VERBOSE > 0

	output("Test passed\n");

#endif

	PASSED;
}
开发者ID:Mellanox,项目名称:arc_ltp,代码行数:65,代码来源:19-11.c

示例2: main

/* Main function */
int main (int argc, char * argv[])
{
	int ret;
	pthread_t th_work, th_sig1, th_sig2;
	thestruct arg1, arg2;
	struct sigaction sa;

	/* Initialize output routine */
	output_init();

	/* We need to register the signal handlers for the PROCESS */
	sigemptyset (&sa.sa_mask);
	sa.sa_flags = 0;
	sa.sa_handler = sighdl1;
	if ((ret = sigaction (SIGUSR1, &sa, NULL)))
	{ UNRESOLVED(ret, "Unable to register signal handler1"); }
	sa.sa_handler = sighdl2;
	if ((ret = sigaction (SIGUSR2, &sa, NULL)))
	{ UNRESOLVED(ret, "Unable to register signal handler2"); }

	/* We prepare a signal set which includes SIGUSR1 and SIGUSR2 */
	sigemptyset(&usersigs);
	ret = sigaddset(&usersigs, SIGUSR1);
	ret |= sigaddset(&usersigs, SIGUSR2);
	if (ret != 0)  {  UNRESOLVED(ret, "Unable to add SIGUSR1 or 2 to a signal set");  }

	/* We now block the signals SIGUSR1 and SIGUSR2 for this THREAD */
	ret = pthread_sigmask(SIG_BLOCK, &usersigs, NULL);
	if (ret != 0)  {  UNRESOLVED(ret, "Unable to block SIGUSR1 and SIGUSR2 in main thread");  }

	#ifdef WITH_SYNCHRO
	if (sem_init(&semsig1, 0, 1))
	{ UNRESOLVED(errno, "Semsig1  init"); }
	if (sem_init(&semsig2, 0, 1))
	{ UNRESOLVED(errno, "Semsig2  init"); }
	#endif

	if ((ret = pthread_create(&th_work, NULL, test, NULL)))
	{ UNRESOLVED(ret, "Worker thread creation failed"); }

	arg1.sig = SIGUSR1;
	arg2.sig = SIGUSR2;
#ifdef WITH_SYNCHRO
	arg1.sem = &semsig1;
	arg2.sem = &semsig2;
#endif

	if ((ret = pthread_create(&th_sig1, NULL, sendsig, (void *)&arg1)))
	{ UNRESOLVED(ret, "Signal 1 sender thread creation failed"); }
	if ((ret = pthread_create(&th_sig2, NULL, sendsig, (void *)&arg2)))
	{ UNRESOLVED(ret, "Signal 2 sender thread creation failed"); }

	/* Let's wait for a while now */
	sleep(1);

	/* Now stop the threads and join them */
	do { do_it=0; }
	while (do_it);

	if ((ret = pthread_join(th_sig1, NULL)))
	{ UNRESOLVED(ret, "Signal 1 sender thread join failed"); }
	if ((ret = pthread_join(th_sig2, NULL)))
	{ UNRESOLVED(ret, "Signal 2 sender thread join failed"); }

	if ((ret = pthread_join(th_work, NULL)))
	{ UNRESOLVED(ret, "Worker thread join failed"); }

	#if VERBOSE > 0
	output("Test executed successfully.\n");
	output("  %d mutex locks.\n", count_ope);
	#ifdef WITH_SYNCHRO
	output("  %d signals were sent meanwhile.\n", count_sig);
	#endif
	#endif
	PASSED;
}
开发者ID:shubmit,项目名称:shub-ltp,代码行数:77,代码来源:4-3.c

示例3: main

int main(int argc, char * argv[])
{
	int ret, i, j;
	struct sigaction sa;

	pthread_mutexattr_t ma;
	pthread_condattr_t ca;
	clockid_t cid = CLOCK_REALTIME;

	testdata_t * td;
	testdata_t alternativ;

	int do_fork;
	long pshared, monotonic, cs, mf;

	pthread_t th[NTOT];

	output_init();

	pshared = sysconf(_SC_THREAD_PROCESS_SHARED);
	cs = sysconf(_SC_CLOCK_SELECTION);
	monotonic = sysconf(_SC_MONOTONIC_CLOCK);
	mf =sysconf(_SC_MAPPED_FILES);

	#if VERBOSE > 0
	output("Test starting\n");
	output("System abilities:\n");
	output(" TPS : %li\n", pshared);
	output(" CS  : %li\n", cs);
	output(" MON : %li\n", monotonic);
	output(" MF  : %li\n", mf);
	if ((mf < 0) || (pshared < 0))
		output("Process-shared attributes won't be tested\n");
	if ((cs < 0) || (monotonic < 0))
		output("Alternative clock won't be tested\n");
	#endif

	/* We are not interested in testing the clock if we have no other clock available.. */
	if (monotonic < 0)
		cs = -1;

#ifndef USE_ALTCLK
	if (cs > 0)
		output("Implementation supports the MONOTONIC CLOCK but option is disabled in test.\n");
#endif

/**********
 * Allocate space for the testdata structure
 */
	if (mf < 0)
	{
		/* Cannot mmap a file, we use an alternative method */
		td = &alternativ;
		pshared = -1; /* We won't do this testing anyway */
		#if VERBOSE > 0
		output("Testdata allocated in the process memory.\n");
		#endif
	}
	else
	{
		/* We will place the test data in a mmaped file */
		char filename[] = "/tmp/cond_timedwait_st1-XXXXXX";
		size_t sz, ps;
		void * mmaped;
		int fd;
		char * tmp;

		/* We now create the temp files */
		fd = mkstemp(filename);
		if (fd == -1)
		{ UNRESOLVED(errno, "Temporary file could not be created"); }

		/* and make sure the file will be deleted when closed */
		unlink(filename);

		#if VERBOSE > 1
		output("Temp file created (%s).\n", filename);
		#endif

		ps = (size_t)sysconf(_SC_PAGESIZE);
		sz= ((sizeof(testdata_t) / ps) + 1) * ps; /* # pages needed to store the testdata */

		tmp = calloc(1 , sz);
		if (tmp == NULL)
		{ UNRESOLVED(errno, "Memory allocation failed"); }

		/* Write the data to the file.  */
		if (write (fd, tmp, sz) != (ssize_t) sz)
		{ UNRESOLVED(sz, "Writting to the file failed"); }

		free(tmp);

		/* Now we can map the file in memory */
		mmaped = mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
		if (mmaped == MAP_FAILED)
		{ UNRESOLVED(errno, "mmap failed"); }

		td = (testdata_t *) mmaped;

		/* Our datatest structure is now in shared memory */
//.........这里部分代码省略.........
开发者ID:andreimironenko,项目名称:ltp-full,代码行数:101,代码来源:stress1.c

示例4: main

/* Main routine */
int main(int argc, char *argv[])
{
	int ret = 0;
	pthread_t child;

	mf = sysconf(_SC_MAPPED_FILES);

	output_init();

	scenar_init();

	/* We want to share some memory with the child process */
	if (mf > 0) {
		/* We will place the test data in a mmaped file */
		char filename[] = "/tmp/pthread_exit_6-1-XXXXXX";
		size_t sz;
		void *mmaped;
		int fd;
		char *tmp;

		/* We now create the temp files */
		fd = mkstemp(filename);
		if (fd == -1) {
			UNRESOLVED(errno,
				   "Temporary file could not be created");
		}

		/* and make sure the file will be deleted when closed */
		unlink(filename);

#if VERBOSE > 1
		output("Temp file created (%s).\n", filename);
#endif

		sz = (size_t) sysconf(_SC_PAGESIZE);

		tmp = calloc(1, sz);
		if (tmp == NULL) {
			UNRESOLVED(errno, "Memory allocation failed");
		}

		/* Write the data to the file.  */
		if (write(fd, tmp, sz) != (ssize_t) sz) {
			UNRESOLVED(sz, "Writting to the file failed");
		}

		free(tmp);

		/* Now we can map the file in memory */
		mmaped =
		    mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
		if (mmaped == MAP_FAILED) {
			UNRESOLVED(errno, "mmap failed");
		}

		ctl = (int *)mmaped;

		/* Our datatest structure is now in shared memory */
#if VERBOSE > 1
		output("Testdata allocated in shared memory.\n");
#endif
	}

	for (sc = 0; sc < NSCENAR; sc++) {
#if VERBOSE > 0
		output("-----\n");
		output("Starting test with scenario (%i): %s\n", sc,
		       scenarii[sc].descr);
#endif

		ret = pthread_create(&child, &scenarii[sc].ta, threaded, &ctl);
		switch (scenarii[sc].result) {
		case 0:	/* Operation was expected to succeed */
			if (ret != 0) {
				UNRESOLVED(ret, "Failed to create this thread");
			}
			break;

		case 1:	/* Operation was expected to fail */
			if (ret == 0) {
				UNRESOLVED(-1,
					   "An error was expected but the thread creation succeeded");
			}
			break;

		case 2:	/* We did not know the expected result */
		default:
#if VERBOSE > 0
			if (ret == 0) {
				output
				    ("Thread has been created successfully for this scenario\n");
			} else {
				output
				    ("Thread creation failed with the error: %s\n",
				     strerror(ret));
			}
#endif
		}
		if (ret == 0) {	/* The new thread is running */
//.........这里部分代码省略.........
开发者ID:Nan619,项目名称:ltp-ddt,代码行数:101,代码来源:6-1.c

示例5: main

/* The main test function. */
int main( int argc, char *argv[] )
{
	int ret = 0;
	pthread_t child;
	pthread_attr_t ta;
	pthread_barrier_t bar;

	struct sched_param sp;

	/* Initialize output routine */
	output_init();

	ret = pthread_barrier_init( &bar, NULL, 2 );

	if ( ret != 0 )
	{
		UNRESOLVED( ret, "Failed to init barrier" );
	}

	/* Create the attribute object with a known scheduling policy */
	ret = pthread_attr_init( &ta );

	if ( ret != 0 )
	{
		UNRESOLVED( ret, "Failed to initialize thread attribute" );
	}

	ret = pthread_attr_setinheritsched( &ta, PTHREAD_EXPLICIT_SCHED );

	if ( ret != 0 )
	{
		UNRESOLVED( ret, "Failed to set inherit sched" );
	}

	sp.sched_priority = sched_get_priority_min( SCHED_RR );

	if ( sp.sched_priority == -1 )
	{
		UNRESOLVED( errno, "Failed to get min priority" );
	}

	ret = pthread_attr_setschedparam( &ta, &sp );

	if ( ret != 0 )
	{
		UNRESOLVED( ret, "Failed to set attribute param" );
	}

	ret = pthread_attr_setschedpolicy( &ta, SCHED_RR );

	if ( ret != 0 )
	{
		UNRESOLVED( ret, "Failed to set attribute policy" );
	}

	/* Create the thread with this attribute */
	ret = pthread_create( &child, &ta, threaded, &bar );

	if ( ret != 0 )
	{
		UNRESOLVED( ret, "thread creation failed (you may need more priviledges)" );
	}

	/* Wait while the thread checks its policy
	  (we only check what is reported, not the real behavior) 
	 */
	check_param( child, SCHED_RR, sched_get_priority_min( SCHED_RR ) );


	ret = pthread_barrier_wait( &bar );

	if ( ( ret != 0 ) && ( ret != PTHREAD_BARRIER_SERIAL_THREAD ) )
	{
		UNRESOLVED( ret, "barrier wait failed" );
	}

	/* Change the threads policy */
	sp.sched_priority = sched_get_priority_min( SCHED_FIFO );

	if ( sp.sched_priority == -1 )
	{
		UNRESOLVED( errno, "Failed to get min priority" );
	}

	ret = pthread_setschedparam( child, SCHED_FIFO, &sp );

	if ( ret != 0 )
	{
		UNRESOLVED( ret, "Failed to change running thread's policy" );
	}

	ret = pthread_barrier_wait( &bar );

	if ( ( ret != 0 ) && ( ret != PTHREAD_BARRIER_SERIAL_THREAD ) )
	{
		UNRESOLVED( ret, "barrier wait failed" );
	}

	/* Wait while the thread checks its policy
//.........这里部分代码省略.........
开发者ID:SummerSnail2014,项目名称:haiku,代码行数:101,代码来源:1-3.c

示例6: main

/* main function */
int main()
{
	int ret;
	pthread_t child;


	struct sigaction sa;

	/* Initialize output */
	output_init();

	/* Set the signal handler */
	sa.sa_flags = SA_RESTART;
	sa.sa_handler = handler;
	ret = sigemptyset( &sa.sa_mask );

	if ( ret != 0 )
	{
		UNRESOLVED( ret, "Failed to empty signal set" );
	}

	/* Install the signal handler for SIGNAL */
	ret = sigaction( SIGNAL, &sa, 0 );

	if ( ret != 0 )
	{
		UNRESOLVED( ret, "Failed to set signal handler" );
	}

	/* Initialize the semaphore */
	ret = sem_init( &sem, 0, 0 );

	if ( ret != 0 )
	{
		UNRESOLVED( ret, "Failed to init a semaphore" );
	}

	/* Create the child thread */
	ret = pthread_create( &child, NULL, threaded, NULL );

	if ( ret != 0 )
	{
		UNRESOLVED( ret, "Failed to create a child thread" );
	}

	/* Let the child thread enter the wait routine...
	  we use sched_yield as there is no certain way to test that the child
	  is waiting for the semaphore... */
	sched_yield();

	sched_yield();

	sched_yield();

	/* Ok, now kill the child */
	ret = pthread_kill( child, SIGNAL );

	if ( ret != 0 )
	{
		UNRESOLVED( ret, "Failed to kill the child thread" );
	}

	/* wait that the child receives the signal */
	while ( !caught )
		sched_yield();

	/* Now let the child run and terminate */
	ret = sem_post( &sem );

	if ( ret != 0 )
	{
		UNRESOLVED( errno, "Failed to post the semaphore" );
	}

	ret = pthread_join( child, NULL );

	if ( ret != 0 )
	{
		UNRESOLVED( ret, "Failed to join the thread" );
	}

	/* terminate */
	ret = sem_destroy( &sem );

	if ( ret != 0 )
	{
		UNRESOLVED( ret, "Failed to destroy the semaphore" );
	}


	/* Test passed */
#if VERBOSE > 0

	output( "Test passed\n" );

#endif

	PASSED;
}
开发者ID:SummerSnail2014,项目名称:haiku,代码行数:100,代码来源:16-8.c

示例7: sigemptyset

void *threaded(void *arg)
{
	pthread_mutexattr_t ma[4], *pma[5];
	pthread_mutex_t m[5];
	int i;
	int ret;

	/* We need to register the signal handlers */
	struct sigaction sa;
	sigemptyset(&sa.sa_mask);
	sa.sa_flags = 0;
	sa.sa_handler = sighdl1;
	if ((ret = sigaction(SIGUSR1, &sa, NULL))) {
		UNRESOLVED(ret, "Unable to register signal handler1");
	}
	sa.sa_handler = sighdl2;
	if ((ret = sigaction(SIGUSR2, &sa, NULL))) {
		UNRESOLVED(ret, "Unable to register signal handler2");
	}

	if ((sem_post(&semsync2))) {
		UNRESOLVED(errno, "could not post semsync2");
	}

	/* Initialize the different mutex */
	pma[4] = NULL;

	for (i = 0; i < 4; i++) {
		pma[i] = &ma[i];
		if ((ret = pthread_mutexattr_init(pma[i]))) {
			UNRESOLVED(ret, "pthread_mutexattr_init");
		}
	}

#ifndef WITHOUT_XOPEN
	if ((ret = pthread_mutexattr_settype(pma[0], PTHREAD_MUTEX_NORMAL))) {
		UNRESOLVED(ret, "pthread_mutexattr_settype (normal)");
	}
	if ((ret = pthread_mutexattr_settype(pma[1], PTHREAD_MUTEX_ERRORCHECK))) {
		UNRESOLVED(ret, "pthread_mutexattr_settype (errorcheck)");
	}
	if ((ret = pthread_mutexattr_settype(pma[2], PTHREAD_MUTEX_RECURSIVE))) {
		UNRESOLVED(ret, "pthread_mutexattr_settype (recursive)");
	}
	if ((ret = pthread_mutexattr_settype(pma[3], PTHREAD_MUTEX_DEFAULT))) {
		UNRESOLVED(ret, "pthread_mutexattr_settype (default)");
	}
#if VERBOSE >1
	output
	    ("Mutex attributes NORMAL,ERRORCHECK,RECURSIVE,DEFAULT initialized\n");
#endif
#else
#if VERBOSE > 0
	output
	    ("Mutex attributes NORMAL,ERRORCHECK,RECURSIVE,DEFAULT unavailable\n");
#endif
#endif

	for (i = 0; i < 5; i++) {
		ret = pthread_mutex_init(&m[i], pma[i]);
		if (ret == EINTR) {
			FAILED("pthread_mutex_init returned EINTR");
		}
		if (ret != 0) {
			UNRESOLVED(ret, "pthread_mutex_init failed");
		}
	}
	/* The mutex are ready, we will loop on lock/unlock now */

	while (do_it) {
		for (i = 0; i < 5; i++) {
			ret = pthread_mutex_lock(&m[i]);
			if (ret == EINTR) {
				FAILED("pthread_mutex_lock returned EINTR");
			}
			if (ret != 0) {
				UNRESOLVED(ret, "pthread_mutex_lock failed");
			}
			ret = pthread_mutex_unlock(&m[i]);
			if (ret == EINTR) {
				FAILED("pthread_mutex_unlock returned EINTR");
			}
			if (ret != 0) {
				UNRESOLVED(ret, "pthread_mutex_unlock failed");
			}
		}
		ret = pthread_mutex_lock(&count_protect);
		if (ret == EINTR) {
			FAILED("pthread_mutex_lock returned EINTR");
		}
		if (ret != 0) {
			UNRESOLVED(ret, "pthread_mutex_lock failed");
		}
		count_ope++;
		pthread_mutex_unlock(&count_protect);
		if (ret == EINTR) {
			FAILED("pthread_mutex_unlock returned EINTR");
		}
		if (ret != 0) {
			UNRESOLVED(ret, "pthread_mutex_unlock failed");
//.........这里部分代码省略.........
开发者ID:Nan619,项目名称:ltp-ddt,代码行数:101,代码来源:3-1.c

示例8: main

/* At last (but not least) we need a main */
int main(int argc, char *argv[])
{
	int ret;
	pthread_t th_work, th_sig1, th_sig2;
	thestruct arg1, arg2;

	output_init();

#ifdef WITH_SYNCHRO
#if VERBOSE >1
	output("Running in synchronized mode\n");
#endif
	if ((sem_init(&semsig1, 0, 1))) {
		UNRESOLVED(errno, "Semsig1  init");
	}
	if ((sem_init(&semsig2, 0, 1))) {
		UNRESOLVED(errno, "Semsig2  init");
	}
#endif

	if ((sem_init(&semsync, 0, 0))) {
		UNRESOLVED(errno, "semsync init");
	}

	if ((sem_init(&semsync2, 0, 0))) {
		UNRESOLVED(errno, "semsync2 init");
	}
#if VERBOSE >1
	output("Starting the worker thread\n");
#endif
	if ((ret = pthread_create(&th_work, NULL, threaded, NULL))) {
		UNRESOLVED(ret, "Worker thread creation failed");
	}

	do {
		ret = sem_wait(&semsync2);
	} while (ret && (errno == EINTR));

	arg1.thr = &th_work;
	arg2.thr = &th_work;
	arg1.sig = SIGUSR1;
	arg2.sig = SIGUSR2;
#ifdef WITH_SYNCHRO
	arg1.sem = &semsig1;
	arg2.sem = &semsig2;
#endif

#if VERBOSE >1
	output("Starting the signal sources\n");
#endif
	if ((ret = pthread_create(&th_sig1, NULL, sendsig, (void *)&arg1))) {
		UNRESOLVED(ret, "Signal 1 sender thread creation failed");
	}
	if ((ret = pthread_create(&th_sig2, NULL, sendsig, (void *)&arg2))) {
		UNRESOLVED(ret, "Signal 2 sender thread creation failed");
	}

	/* Let's wait for a while now */
#if VERBOSE >1
	output("Let the worker be killed for a second\n");
#endif
	sleep(1);

	/* Now stop the threads and join them */
#if VERBOSE >1
	output("Stop everybody\n");
#endif
	do {
		do_it = 0;
	}
	while (do_it);

	if ((ret = pthread_join(th_sig1, NULL))) {
		UNRESOLVED(ret, "Signal 1 sender thread join failed");
	}
	if ((ret = pthread_join(th_sig2, NULL))) {
		UNRESOLVED(ret, "Signal 2 sender thread join failed");
	}
#if VERBOSE >1
	output("Signal sources are stopped, we can stop the worker\n");
#endif
	if ((sem_post(&semsync))) {
		UNRESOLVED(errno, "could not post semsync");
	}

	if ((ret = pthread_join(th_work, NULL))) {
		UNRESOLVED(ret, "Worker thread join failed");
	}
#if VERBOSE > 0
	output("Test executed successfully.\n");
	output("  %d mutex lock and unlock were done.\n", count_ope);
#ifdef WITH_SYNCHRO
	output("  %d signals were sent meanwhile.\n", count_sig);
#endif
#endif
	PASSED;
}
开发者ID:Nan619,项目名称:ltp-ddt,代码行数:98,代码来源:3-1.c

示例9: main

/* The main test function. */
int main(int argc, char * argv[])
{
	int ret, status;
	pid_t child, ctl;
	int fd;
	void *buf;
	sem_t * sem;

	/* Initialize output */
	output_init();

	/* Create the shared memory segment */
	fd = shm_open("/sem_init_3-2", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);

	if (fd == -1)
	{
		UNRESOLVED(errno, "Failed to open shared memory segment");
	}

	/* Size the memory segment to 1 page size. */
	ret = ftruncate(fd, sysconf(_SC_PAGESIZE));

	if (ret != 0)
	{
		UNRESOLVED(errno, "Failed to size the shared memory segment");
	}

	/* Map these sengments in the process memory space */
	buf = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);

	if (buf == MAP_FAILED)
	{
		UNRESOLVED(errno, "Failed to mmap the shared memory segment");
	}

	sem = (sem_t *) buf;

	/* Initialize the semaphore */
	ret = sem_init(sem, 1, 0);

	if (ret != 0)
	{
		UNRESOLVED(errno, "Failed to init the semaphore");
	}

	/* Create the child */
	child = fork();

	if (child == -1)
	{
		UNRESOLVED(errno, "Failed to fork");
	}

	/* child */
	if (child == 0)
	{
		/* Post the sempahore */
		ret = sem_post(sem);

		if (ret != 0)
		{
			UNRESOLVED(errno, "Failed to post the semaphore");
		}

		/* We're done */
		exit(PTS_PASS);
	}

	/* Wait the sempahore */
	do {
		ret = sem_wait(sem);
	} while (ret != 0 && errno == EINTR);

	if (ret != 0)
	{
		UNRESOLVED(errno, "Failed to wait for the semaphore");
	}

	/* Parent joins the child */
	ctl = waitpid(child, &status, 0);

	if (ctl != child)
	{
		UNRESOLVED(errno, "Waitpid returned the wrong PID");
	}

	if (!WIFEXITED(status) || (WEXITSTATUS(status) != PTS_PASS))
	{
		FAILED("Child exited abnormally");
	}

	/* Clean things */
	ret = sem_destroy(sem);

	if (ret != 0)
	{
		UNRESOLVED(errno, "Failed to destroy the semaphore");
	}

//.........这里部分代码省略.........
开发者ID:shubmit,项目名称:shub-ltp,代码行数:101,代码来源:3-2.c

示例10: main

/* The main test function. */
int main(int argc, char *argv[])
{
	int ret, i;
	sem_t *sems;
	sem_t sem_last;

	long max;

	/* Initialize output */
	output_init();

	max = sysconf(_SC_SEM_NSEMS_MAX);

	if (max <= 0) {
		output("sysconf(_SC_SEM_NSEMS_MAX) = %ld\n", max);
		UNTESTED("There is no constraint on SEM_NSEMS_MAX");
	}

	sems = (sem_t *) calloc(max, sizeof(sem_t));

	if (sems == NULL) {
		UNRESOLVED(errno, "Failed to alloc space");
	}

	for (i = 0; i < max; i++) {
		ret = sem_init(&sems[i], 0, 0);

		if (ret != 0) {
			output
			    ("sem_init failed to initialize the %d nth semaphore.\n",
			     i);
			output("Tryed to initialize %ld.\n", max);
			output("Error is %d: %s\n", errno, strerror(errno));

			for (; i > 0; i--)
				sem_destroy(&sems[i - 1]);

			free(sems);

			PASSED;
		}
	}

	ret = sem_init(&sem_last, 0, 1);

	if (ret == 0) {
		FAILED
		    ("We were able to sem_init more than SEM_NSEMS_MAX semaphores");
	}

	if (errno != ENOSPC) {
		output("Error is %d: %s\n", errno, strerror(errno));
	}

	for (i = 0; i < max; i++)
		sem_destroy(&sems[i]);

	free(sems);

	/* Test passed */
#if VERBOSE > 0

	output("Test passed\n");

#endif

	PASSED;
}
开发者ID:Nan619,项目名称:ltp-ddt,代码行数:69,代码来源:7-1.c

示例11: main

int main (int argc, char * argv[])
{
	int ret;

	pthread_mutexattr_t ma;
	pthread_condattr_t ca;

	int scenar;
	long pshared, monotonic, cs, mf;

	pid_t p_child[NTHREADS];
	pthread_t t_child[NTHREADS];
	int ch;
	pid_t pid;
	int status;

	pthread_t t_timer;

	testdata_t alternativ;

	output_init();

	/* check the system abilities */
	pshared = sysconf(_SC_THREAD_PROCESS_SHARED);
	cs = sysconf(_SC_CLOCK_SELECTION);
	monotonic = sysconf(_SC_MONOTONIC_CLOCK);
	mf =sysconf(_SC_MAPPED_FILES);

	#if VERBOSE > 0
	output("Test starting\n");
	output("System abilities:\n");
	output(" TPS : %li\n", pshared);
	output(" CS  : %li\n", cs);
	output(" MON : %li\n", monotonic);
	output(" MF  : %li\n", mf);
	if ((mf < 0) || (pshared < 0))
		output("Process-shared attributes won't be tested\n");
	if ((cs < 0) || (monotonic < 0))
		output("Alternative clock won't be tested\n");
	#endif

	/* We are not interested in testing the clock if we have no other clock available.. */
	if (monotonic < 0)
		cs = -1;

#ifndef USE_ALTCLK
	if (cs > 0)
		output("Implementation supports the MONOTONIC CLOCK but option is disabled in test.\n");
#endif

/**********
 * Allocate space for the testdata structure
 */
	if (mf < 0)
	{
		/* Cannot mmap a file, we use an alternative method */
		td = &alternativ;
		pshared = -1; /* We won't do this testing anyway */
		#if VERBOSE > 0
		output("Testdata allocated in the process memory.\n");
		#endif
	}
	else
	{
		/* We will place the test data in a mmaped file */
		char filename[] = "/tmp/cond_destroy-XXXXXX";
		size_t sz, ps;
		void * mmaped;
		int fd;
		char * tmp;

		/* We now create the temp files */
		fd = mkstemp(filename);
		if (fd == -1)
		{ UNRESOLVED(errno, "Temporary file could not be created"); }

		/* and make sure the file will be deleted when closed */
		unlink(filename);

		#if VERBOSE > 1
		output("Temp file created (%s).\n", filename);
		#endif

		ps = (size_t)sysconf(_SC_PAGESIZE);
		sz= ((sizeof(testdata_t) / ps) + 1) * ps; /* # pages needed to store the testdata */

		tmp = calloc(1 , sz);
		if (tmp == NULL)
		{ UNRESOLVED(errno, "Memory allocation failed"); }

		/* Write the data to the file.  */
		if (write (fd, tmp, sz) != (ssize_t) sz)
		{ UNRESOLVED(sz, "Writting to the file failed"); }

		free(tmp);

		/* Now we can map the file in memory */
		mmaped = mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
		if (mmaped == MAP_FAILED)
		{ UNRESOLVED(errno, "mmap failed"); }
//.........这里部分代码省略.........
开发者ID:barajas,项目名称:Intel-GLTP,代码行数:101,代码来源:2-1.c

示例12: child

/* Child function (either in a thread or in a process) */
void * child(void * arg)
{
	int ret=0;
	struct timespec ts;
	char timed;

	/* lock the 1st mutex */
	ret = pthread_mutex_lock(&td->mtx1);
	if (ret != 0)  {  UNRESOLVED(ret, "Failed to lock mutex in child");  }

	/* increment count */
	td->count1++;

	timed=td->count1 & 1;

	if (timed)
	{
	/* get current time if we are a timedwait */
		ret = clock_gettime(td->cid, &ts);
		if (ret != 0)  {  UNRESOLVED(errno, "Unable to read clock");  }
		ts.tv_sec += TIMEOUT;
	}

	do {
	/* Wait while the predicate is false */
		if (timed)
			ret = pthread_cond_timedwait(&td->cnd, &td->mtx1, &ts);
		else
			ret = pthread_cond_wait(&td->cnd, &td->mtx1);
	} while ((ret == 0) && (td->predicate1==0));
	if ((ret != 0) && (td->predicate1 != 0))
	{
		output("Wakening the cond failed with error %i (%s)\n", ret, strerror(ret));
		FAILED("Destroying the cond var while threads were awaken but inside wait routine failed.");
	}
	if (ret != 0)  {  UNRESOLVED(ret, "Failed to wait for the cond");  }

	td->count1--;

	/* unlock the mutex */
	ret = pthread_mutex_unlock(&td->mtx1);
	if (ret != 0)  {  UNRESOLVED(ret, "Failed to unlock the mutex.");  }

  /* Second pass */

	/* lock the mutex */
	ret = pthread_mutex_lock(&td->mtx2);
	if (ret != 0)  {  UNRESOLVED(ret, "Failed to lock mutex in child");  }

	/* increment count */
	td->count2++;

	timed=td->count2 & 1;

	if (timed)
	{
	/* get current time if we are a timedwait */
		ret = clock_gettime(td->cid, &ts);
		if (ret != 0)  {  UNRESOLVED(errno, "Unable to read clock");  }
		ts.tv_sec += TIMEOUT;
	}

	do {
	/* Wait while the predicate is false */
		if (timed)
			ret = pthread_cond_timedwait(&td->cnd, &td->mtx2, &ts);
		else
			ret = pthread_cond_wait(&td->cnd, &td->mtx2);
	} while ((ret == 0) && (td->predicate2==0));
	if ((ret != 0) && (td->predicate2 != 0))
	{
		output("Wakening the cond failed with error %i (%s)\n", ret, strerror(ret));
		FAILED("Destroying the cond var while threads were awaken but inside wait routine failed.");
	}
	if (ret != 0)  {  UNRESOLVED(ret, "Failed to wait for the cond");  }

	/* unlock the mutex */
	ret = pthread_mutex_unlock(&td->mtx2);
	if (ret != 0)  {  UNRESOLVED(ret, "Failed to unlock the mutex.");  }

	return NULL;
}
开发者ID:barajas,项目名称:Intel-GLTP,代码行数:83,代码来源:2-1.c

示例13: main

/* The main test function. */
int main(void)
{
	int ret, i;
	char *name = "/sem_open_15_1";

	sem_t *sems[4];

	/* Initialize output */
	output_init();

	/* Initialize all semaphores */

	for (i = 0; i < 4; i++) {
		sems[i] = sem_open(name, O_CREAT, 0777, 1);

		if (sems[i] == SEM_FAILED) {
			UNRESOLVED(errno, "Failed to sem_open");
		}

	}

	/* Check all calls returned the same @ */
	for (i = 0; i < 3; i++) {
		if (sems[i] != sems[i + 1]) {
			FAILED("sem_open returned a different address");
		}

		/* Close some semaphores */
		ret = sem_close(sems[i]);

		if (ret != 0) {
			UNRESOLVED(errno, "Failed to sem_close");
		}
	}

	/* Now, reopen, we should still get the same address */
	for (i = 0; i < 3; i++) {
		sems[i] = sem_open(name, O_CREAT, 0777, 1);

		if (sems[i] == SEM_FAILED) {
			UNRESOLVED(errno, "Failed to sem_open");
		}

	}

	/* Check all calls returned the same @ */
	for (i = 0; i < 3; i++) {
		if (sems[i] != sems[i + 1]) {
			FAILED("sem_open returned a different address");
		}
	}

	/* Close all semaphores */
	for (i = 0; i < 4; i++) {
		ret = sem_close(sems[i]);

		if (ret != 0) {
			UNRESOLVED(errno, "Failed to sem_close");
		}
	}

	sem_unlink(name);

	/* Test passed */
#if VERBOSE > 0

	output("Test passed\n");

#endif

	PASSED;
}
开发者ID:kraj,项目名称:ltp,代码行数:73,代码来源:15-1.c

示例14: threaded

void * threaded(void * arg)
{
	pthread_condattr_t ca[4], *pca[5];
	pthread_cond_t c[5];
	int i;
	int ret;

	/* We need to register the signal handlers */
	struct sigaction sa;
	sigemptyset (&sa.sa_mask);
	sa.sa_flags = 0;
	sa.sa_handler = sighdl1;
	if ((ret = sigaction (SIGUSR1, &sa, NULL)))
	{ UNRESOLVED(ret, "Unable to register signal handler1"); }
	sa.sa_handler = sighdl2;
	if ((ret = sigaction (SIGUSR2, &sa, NULL)))
	{ UNRESOLVED(ret, "Unable to register signal handler2"); }

	/* Initialize the different cond attributes */
	pca[4]=NULL;

	for (i=0; i<4; i++)
	{
		pca[i]=&ca[i];
		if ((ret = pthread_condattr_init(pca[i])))
		{ UNRESOLVED(ret, "pthread_condattr_init"); }
	}

		ret = pthread_condattr_setpshared(pca[0], PTHREAD_PROCESS_SHARED);
		if (ret != 0) {  UNRESOLVED(ret, "Cond attribute PSHARED failed");  }
		ret = pthread_condattr_setpshared(pca[1], PTHREAD_PROCESS_SHARED);
		if (ret != 0) {  UNRESOLVED(ret, "Cond attribute PSHARED failed");  }

		#if VERBOSE >1
		output("PShared condvar attributes initialized\n");
		#endif
		if (sysconf(_SC_MONOTONIC_CLOCK) > 0)
		{
			ret = pthread_condattr_setclock(pca[1], CLOCK_MONOTONIC);
			if (ret != 0) {  UNRESOLVED(ret, "Cond set monotonic clock failed");  }
			ret = pthread_condattr_setclock(pca[2], CLOCK_MONOTONIC);
			if (ret != 0) {  UNRESOLVED(ret, "Cond set monotonic clock failed");  }
			#if VERBOSE >1
			output("Alternative clock condvar attributes initialized\n");
			#endif
		}

	/*	We are ready to proceed */
	while (do_it)
	{
		for (i=0; i<5; i++)
		{
			ret = pthread_cond_init(&c[i], pca[i]);
			if (ret == EINTR)
			{
				FAILED("pthread_cond_init returned EINTR");
			}
			if (ret != 0)
			{
				UNRESOLVED(ret, "pthread_cond_init failed");
			}
			ret = pthread_cond_destroy(&c[i]);
			if (ret == EINTR)
			{
				FAILED("pthread_cond_destroy returned EINTR");
			}
			if (ret != 0)
			{
				UNRESOLVED(ret, "pthread_cond_destroy failed");
			}
			pthread_mutex_lock(&count_protect);
			count_ope++;
			pthread_mutex_unlock(&count_protect);
		}
	}

	/* Now we can destroy the mutex attributes objects */
	for (i=0; i<4; i++)
	{
		if ((ret = pthread_condattr_destroy(pca[i])))
		{ UNRESOLVED(ret, "pthread_condattr_init"); }
	}

	do {
		ret = sem_wait(&semsync);
	} while (ret && (errno ==  EINTR));
	if (ret)
	{ UNRESOLVED(errno, "Could not wait for sig senders termination"); }

	return NULL;
}
开发者ID:Nan619,项目名称:ltp-ddt,代码行数:91,代码来源:4-2.c

示例15: main

int main(int argc, char *argv[])
{
	int ret;
	pthread_t th_work, th_sig1, th_sig2;
	struct thestruct arg1, arg2;

	struct sigaction sa;

	output_init();

	sigemptyset(&sa.sa_mask);
	sa.sa_flags = 0;
	sa.sa_handler = sighdl1;

	ret = sigaction(SIGUSR1, &sa, NULL);
	if (ret == -1)
		UNRESOLVED(ret, "Unable to register signal handler1");

	sa.sa_handler = sighdl2;
	ret = sigaction(SIGUSR2, &sa, NULL);
	if (ret == -1)
		UNRESOLVED(ret, "Unable to register signal handler2");

	/* We prepare a signal set which includes SIGUSR1 and SIGUSR2 */
	sigemptyset(&usersigs);

	ret = sigaddset(&usersigs, SIGUSR1);
	ret |= sigaddset(&usersigs, SIGUSR2);
	if (ret != 0)
		UNRESOLVED(ret, "Unable to add SIGUSR1 or 2 to a signal set");

	/* We now block the signals SIGUSR1 and SIGUSR2 for this THREAD */
	ret = pthread_sigmask(SIG_BLOCK, &usersigs, NULL);
	if (ret != 0)
		UNRESOLVED(ret, "Unable to block SIGUSR1 and SIGUSR2 "
			   "in main thread");

#ifdef WITH_SYNCHRO
	if (sem_init(&semsig1, 0, 1))
		UNRESOLVED(errno, "Semsig1  init");

	if (sem_init(&semsig2, 0, 1))
		UNRESOLVED(errno, "Semsig2  init");

#endif

	/* Initialize thread attribute objects */
	scenar_init();

	ret = pthread_create(&th_work, NULL, test, NULL);
	if (ret)
		UNRESOLVED(ret, "Worker thread creation failed");

	arg1.sig = SIGUSR1;
	arg2.sig = SIGUSR2;
#ifdef WITH_SYNCHRO
	arg1.sem = &semsig1;
	arg2.sem = &semsig2;
#endif

	ret = pthread_create(&th_sig1, NULL, sendsig, (void *)&arg1);
	if (ret)
		UNRESOLVED(ret, "Signal 1 sender thread creation failed");

	ret = pthread_create(&th_sig2, NULL, sendsig, (void *)&arg2);
	if (ret)
		UNRESOLVED(ret, "Signal 2 sender thread creation failed");

	/* Now stop the threads and join them */
	do {
		do_it1 = 0;
	} while (do_it1);

	sleep(1);

	do {
		do_it2 = 0;
	} while (do_it2);

	ret = pthread_join(th_sig1, NULL);
	if (ret)
		UNRESOLVED(ret, "Signal 1 sender thread join failed");

	ret = pthread_join(th_sig2, NULL);
	if (ret)
		UNRESOLVED(ret, "Signal 2 sender thread join failed");

	ret = pthread_join(th_work, NULL);
	if (ret)
		UNRESOLVED(ret, "Worker thread join failed");

	scenar_fini();

#if VERBOSE > 0
	output("Test executed successfully.\n");

	output("  %d pthread_join calls.\n", count_ope);

#ifdef WITH_SYNCHRO
	output("  %d signals were sent meanwhile.\n", count_sig);
//.........这里部分代码省略.........
开发者ID:Nan619,项目名称:ltp-ddt,代码行数:101,代码来源:6-3.c


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