コード例 #1
0
ファイル: muti_thr.c プロジェクト: jindal25/Coding4cpp
void * sub_e(void *arg)
{
int i;
thread_t ret_thr;
void *status;

printf("E: In thread E...\n"); 
printf("E: Join A thread\n"); 

if(thr_join(thr_a,(thread_t *)&ret_thr, &status)) 
        fprintf(stderr,"thr_join Error\n"), exit(1);

printf("E: A thread (%d) returned thread (%d) w/status %d\n", ret_thr, ret_thr, (int) status); 
printf("E: Join B thread\n"); 

if(thr_join(thr_b,(thread_t *)&ret_thr, &status)) 
        fprintf(stderr,"thr_join Error\n"), exit(1);

printf("E: B thread (%d) returned thread (%d) w/status %d\n", thr_b, ret_thr, (int) status); 
printf("E: Join C thread\n"); 

if(thr_join(thr_c,(thread_t *)&ret_thr, &status)) 
        fprintf(stderr,"thr_join Error\n"), exit(1);

printf("E: C thread (%d) returned thread (%d) w/status %d\n", thr_c, ret_thr, (int) status); 

for (i=0;i<1000000*(int)thr_self();i++);

printf("E: Thread exiting...\n"); 
thr_exit((void *)44);
}
コード例 #2
0
ファイル: juggle.c プロジェクト: xiaozhuyfk/Pebble_Kernel
/** @brief The workhorse thread of the test.
 *
 *  This thread recursively spawns two copies of itself decrementing n_voidstar
 *  so long as n_voidstar is positive. Each thread repeats this process n_throws
 *  times, after joining on the threads it created.
 *
 *  @param The level we are at (to keep us from infinitly recursively spawning.
 */
void *juggle(void * n_voidstar)
{
    int sub1, sub2;
    int throws;
    int substat;
    int ret;
    int n = (int)n_voidstar;

    inc_count();
    print_count(n);

    if (n > 0) {
        for (throws = 0; throws < n_throws; throws++) {
    
            // Toss up two balls
            sub1 = thr_create(juggle, (void *)(n - 1));
        
            if (sub1 < 0) {
                lprintf("Lev %d failed to create first thread w/ err %d\n",
                        n, sub1);
            }
    
            sub2 = thr_create(juggle, (void *)(n - 1));
    
            if (sub2 < 0) {
                lprintf("Lev %d failed to create second thread w/ err %d\n",
                        n, sub2);
            }
    
            // Try to catch them
            if ((ret = thr_join(sub1, (void*)&substat))
                 != 0 || substat != (n - 1)) {
              lprintf("Lev %d failed to join first thread correctly:\n\t", n);
              lprintf("join(%d), ret = %d, %d ?= %d\n",
                                    sub1, ret, (n - 1), substat);
            }
            
            if ((ret = thr_join(sub2, (void*)&substat))
                != 0 || substat != (n - 1)) {
              lprintf("Lev %d failed to join second thread correctly:\n\t", n);
              lprintf("join(%d), ret = %d, %d ?= %d\n",
                                    sub2, ret, (n - 1), substat);
            }
        }
    }
#ifdef PRINT
    // Tell that we were successfull.
    putchar((char)n + '0');
#endif

    print_count(n);

    // Hang in the air for some amount of time
    sleep(genrand() % SLEEP_MAX);
    
    return (void *)n;
}
コード例 #3
0
ファイル: muti_thr.c プロジェクト: jindal25/Coding4cpp
void * sub_d(void *arg)
{
thread_t thr_b = (thread_t) arg;
int i;
thread_t thr_e, ret_thr;
void *status;

printf("D: In thread D...\n"); 

if (thr_create(NULL, 0, sub_e, NULL, THR_NEW_LWP, &thr_e))
        fprintf(stderr,"Can't create thr_e\n"), exit(1);

printf("D: Created thread E:%d\n", thr_e); 
printf("D: Continue B thread = %d\n", thr_b); 

thr_continue(thr_b);
printf("D: Join E thread\n"); 

if(thr_join(thr_e,(thread_t *)&ret_thr, &status)) 
        fprintf(stderr,"thr_join Error\n"), exit(1);

printf("D: E thread (%d) returned thread (%d) w/status %d\n", thr_e, 
ret_thr, (int) status); 

/* process 
*/

for (i=0;i<1000000*(int)thr_self();i++);
printf("D: Thread exiting...\n"); 
thr_exit((void *)55);
}
コード例 #4
0
ファイル: main.cpp プロジェクト: pp7462-git/sandbox
void 
main(int argc, char** argv)
{

	if (argc != 3 )
    {
		cerr <<"Usage " << argv[0]<< "<BUF_SIZE> < # of THREAD>"<<endl;
		return;
    }

	long flag = THR_DETACHED|THR_NEW_LWP;
	MemRegisterTask();
	new int;
	MemInitDefaultPool();
	MEM_POOL_INFO info;
	MemPoolInfo(MemDefaultPool, NULL, &info);
	printf("def pool pageSize: %d;"
     "blockSizeFS: %hd\n",
     info.pageSize, info.blockSizeFS);

	long long buf_size = atoll(argv[1]);
	int no_of_threads = atoi(argv[2]);

	thread_t t1;
    for(int i=0;i<no_of_threads;i++)
    {
	    thr_create(NULL,0,thr_RUN,(void*)&buf_size,flag, &t1);
    }
    while (thr_join(NULL, NULL, NULL)==0);

	return;
}
コード例 #5
0
ファイル: muti_thr.c プロジェクト: jindal25/Coding4cpp
void * sub_c(void *arg)
{
void *status;
int i;
thread_t main_thr, ret_thr;

main_thr = (thread_t)arg;

printf("C: In thread C...\n"); 

if (thr_create(NULL, 0, sub_f, (void *)0, THR_BOUND|THR_DAEMON, NULL))
        fprintf(stderr, "Can't create thr_f\n"), exit(1);

printf("C: Join main thread\n"); 

if (thr_join(main_thr,(thread_t *)&ret_thr, &status)) 
        fprintf(stderr, "thr_join Error\n"), exit(1);

printf("C: Main thread (%d) returned thread (%d) w/status %d\n", main_thr, ret_thr, (int) status); 

/* process 
*/

for (i=0;i<1000000*(int)thr_self();i++);
printf("C: Thread exiting...\n"); 
thr_exit((void *)88);
}
コード例 #6
0
void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx)
	{
	SSL_CTX *ssl_ctx[2];
	thread_t thread_ctx[MAX_THREAD_NUMBER];
	int i;

	ssl_ctx[0]=s_ctx;
	ssl_ctx[1]=c_ctx;

	thr_setconcurrency(thread_number);
	for (i=0; i<thread_number; i++)
		{
		thr_create(NULL, THREAD_STACK_SIZE,
			(void *(*)())ndoit,
			(void *)ssl_ctx,
			0L,
			&(thread_ctx[i]));
		}

	printf("reaping\n");
	for (i=0; i<thread_number; i++)
		{
		thr_join(thread_ctx[i],NULL,NULL);
		}

	printf("solaris threads done (%d,%d)\n",
		s_ctx->references,c_ctx->references);
	}
コード例 #7
0
ファイル: test_thr.c プロジェクト: dlbeer/libdlb
int main(void)
{
	int my_count = 5;

	thr_mutex_init(&mutex);
	if (thr_event_init(&event) < 0) {
		report_syserr("thr_event_init");
		return -1;
	}

	thr_start(&worker, work_func, NULL);
	while (my_count) {
		thr_mutex_lock(&mutex);
		counter++;
		my_count--;
		printf("producer: counter++\n");
		thr_mutex_unlock(&mutex);
		thr_event_raise(&event);
		clock_wait(10);
	}
	thr_join(worker);

	test_timedwait();

	thr_event_destroy(&event);
	thr_mutex_destroy(&mutex);
	return 0;
}
コード例 #8
0
ファイル: taskq.c プロジェクト: BjoKaSH/mac-zfs
void
taskq_destroy(taskq_t *tq)
{
	int t;
	int nthreads = tq->tq_nthreads;

	taskq_wait(tq);

	mutex_enter(&tq->tq_lock);

	tq->tq_flags &= ~TASKQ_ACTIVE;
	cv_broadcast(&tq->tq_dispatch_cv);

	while (tq->tq_nthreads != 0)
		cv_wait(&tq->tq_wait_cv, &tq->tq_lock);

	tq->tq_minalloc = 0;
	while (tq->tq_nalloc != 0) {
		ASSERT(tq->tq_freelist != NULL);
		task_free(tq, task_alloc(tq, KM_SLEEP));
	}

	mutex_exit(&tq->tq_lock);

	for (t = 0; t < nthreads; t++)
		(void) thr_join(tq->tq_threadlist[t], NULL, NULL);

	kmem_free(tq->tq_threadlist, nthreads * sizeof (thread_t));

	rw_destroy(&tq->tq_threadlock);

	kmem_free(tq, sizeof (taskq_t));
}
コード例 #9
0
ファイル: thrgrp.c プロジェクト: kikimo/pebble
/** @brief joins on any thread which exits in the group
 * 
 * like thr_join(), but will join on any exited thread which was spawned into 
 * this thread group via thrgrp_create()
 * 
 * throughout this function thrgrp_queue_el_t is a LIE! in reality this is
 * thrgrp_data_t, a union including thrgrp_queue_el_t as a subtype. this is
 * only important because one should realize "free" is freeing thrgrp_data_t
 * of memory, not thrgrp_queue_el_t of memory
 *
 * @param eg, an initialized thread group to join on threads in
 * @param depared, a pointer to some memory, the TID of the exited
 * thread will be placed here before thrgrp_join returns
 * @param status, a pointer to a void *, where the return status of
 * the thread we join on (I.E. what's returned from that threads first function
 * @return returns the result of thr_join
 */
int thrgrp_join(thrgrp_group_t* eg, void **status){
  thrgrp_queue_el_t *thr_data;
  int tid;

  mutex_lock(&(eg->lock));
  /* check to see if there's someone to join on*/
  while(eg->zombie_out == NULL){
    /* wait until there is someone to join on */
    if(cond_wait(&(eg->cv),&(eg->lock))){
      panic("thrgrp_join: cond_wait failed... we're BORKEN!!\n");
    }
    /* inside of cond_wait, someone can sneek in
     * I.E. even if condition variables are implemented in order 
     * we do not have guaranteed in order joins */
  }
  /* get our zombie from the queue */
  thr_data = eg->zombie_out;
  if(eg->zombie_out == eg->zombie_in){
    eg->zombie_in = NULL;
    eg->zombie_out = NULL;
  }else{
    eg->zombie_out = eg->zombie_out->next;
  }
  mutex_unlock(&(eg->lock));

  /* grab the tid out before we free it */
  tid = thr_data->tid;
  /* free the memory from the queue */
  free(thr_data);
  /* join on the tid, and return the result */
  return thr_join(tid, status);
}
コード例 #10
0
ファイル: thread_1.c プロジェクト: North114/SocketReceiver
int main(){
	printf("parent:begin\n");
	pthread_t c;
	pthread_create(&c,NULL,child,NULL);
	thr_join();
	printf("parent:end\n");

	return 0;
}
コード例 #11
0
int main(int argc, char *argv[]){
  printf("parent: begin\n");
  pthread_t p;
  int rc=pthread_create(&p,NULL,&child,NULL);
  assert(rc==0);
  thr_join();
  printf("parent: end\n");
  return 0;

}
コード例 #12
0
ファイル: excepmttest.cpp プロジェクト: pp7462-git/sandbox
int main()
{
	int threads=5;
	thread_t tid[5];
	for(int i=0; i<threads; i++)
	{
		thr_create(NULL,0,Run,NULL,0,&tid[i]);
	}
	while(thr_join(NULL,NULL,NULL)==0);
	return 0;
}
コード例 #13
0
void *
waiter(void *p)
{
  int status;
  
  thr_join((int)p, (void **)&status);
  //printf("Thread %d exited '%c'\n", (int)p, (char)status);
  
  thr_exit((void *) 0);

  while(1)
	continue; /* placate compiler portably */
}
コード例 #14
0
ファイル: crawler.c プロジェクト: subasreev/cs537
int
crawl (char *start_url,
       int download_workers,
       int parse_workers,
       int queue_size,
       char *(*_fetch_fn) (char *url),
       void (*_edge_fn) (char *from, char *to))
{

  QUEUE_SIZE = queue_size;
  queue_links = (char **) malloc (sizeof (char *) * queue_size);
  queue_pages = (list_t *) malloc (sizeof (list_t));
  List_Init (queue_pages);
  urls = create_hash_table(65535); //hash set for unique urls

  //add start_url to bounded queue
  //printf("start url = %s\n", start_url);
  put (start_url);
  add_string(urls, start_url);

/*
  char *seed_url = NULL;
  lst_t *l = lookup_string(urls, start_url);  
  if(l!=NULL)
	  seed_url = l->string;
  if(seed_url != NULL)
	printf("seed url=%s\n",seed_url);
  else
	printf("not found\n");
*/
  //set sum_queue_lengths to 1
  sum_queue_lengths = 1;
 

  //create threads
  pthread_t downloaders[download_workers], parsers[parse_workers];
  int i;
  //printf("creating threads\n");

  for (i = 0; i < download_workers; i++)
    pthread_create (&downloaders[i], NULL, download, _fetch_fn);

  for (i = 0; i < parse_workers; i++)
    pthread_create (&parsers[i], NULL, parse, _edge_fn);

  //printf("created threads\n");
  thr_join ();
  
  printf ("crawler completed successfully\n");
  return 0;
}
コード例 #15
0
ファイル: mttest.c プロジェクト: dhaley/dcp
void
thread_work()
{
	int i;

#ifdef UNBOUND
    #ifdef SOLARIS
	if (thr_setconcurrency(nthreads) != 0) {
		perror("Oops, thr_setconcurrency failed");
		exit(1);
	}
    #endif
#endif

	/* create nthreads threads, having each start at do_work */
	for (i = 0; i < nthreads; i++) {
		int retval;

#ifdef SOLARIS
    #ifdef BOUND
		retval = thr_create(0, 0, do_work, 0, THR_BOUND, &(tid[i]));
    #endif
    #ifdef UNBOUND
		retval = thr_create(0, 0, do_work, 0, 0, &(tid[i]));
    #endif
#endif
#ifdef POSIX
    #ifdef BOUND
		retval = pthread_create(&(tid[i]), &attr, do_work, 0);
    #endif
    #ifdef UNBOUND
		retval = pthread_create(&(tid[i]), 0, do_work, 0);
    #endif
#endif

		if(retval != 0) {
			perror("Oops, thr_create failed");
			exit(1);
		}
	}

	/* wait for all threads to complete their work and join */
	for (i = 0; i < nthreads; i++) {
#ifdef SOLARIS
		thr_join(tid[i], 0, 0);
#endif
#ifdef POSIX
		pthread_join(tid[i], 0);
#endif
	}
}
コード例 #16
0
/****************************************************************************
 * Main function
 ****************************************************************************/
int main() {

	thread_t *producers;
	thread_t *consumers;
	thread_t tid;
	int *prod_ids;
	int *cons_ids;
	SPC *status;
	int x;

	signal(SIGALRM, SIG_IGN);

	producers = (thread_t*)malloc(sizeof(thread_t) * NUMBER_PRODUCERS);
	consumers = (thread_t*)malloc(sizeof(thread_t) * NUMBER_CONSUMERS);
	prod_ids = (int*)malloc(sizeof(int) * NUMBER_PRODUCERS);
	cons_ids = (int*)malloc(sizeof(int) * NUMBER_CONSUMERS);
	buffer = (int*)malloc(sizeof(int) * BUFFER_SIZE);

	/* Create the producer threads */
	for(x = 0; x < NUMBER_PRODUCERS; x++) {
		prod_ids[x] = x + 1;
		thr_create(NULL, NULL, Producer, &prod_ids[x], 0, &producers[x]);
	}

	/* Create the consumer threads */
	for(x = 0; x < NUMBER_CONSUMERS; x++) {
		cons_ids[x] = x + 1;
		thr_create(NULL, NULL, Consumer, &cons_ids[x], 0, &consumers[x]);
	}

	/* Wait for the threads to finish */
	for(x = 0; x < NUMBER_PRODUCERS + NUMBER_CONSUMERS; x++) {
		thr_join(0, &tid, (void**)&status);
		if(status->type == PRODUCER) {
			printf("main(): PRODUCER-%d joined. %d widgets created.\n",
				status->id, status->num);
		} else {
			printf("main(): CONSUMER-%d joined. %d widgets consumed.\n",
				status->id, status->num);
		}
	}

	free(producers);
	free(consumers);
	free(prod_ids);
	free(cons_ids);
	free(buffer);

	return 0;
}
コード例 #17
0
ファイル: htm_causality.c プロジェクト: bblum/landslide
int main(void)
{
	report_start(START_CMPLT);

	ERR(thr_init(4096));

	int tid = thr_create(child, NULL);
	thr_yield(-1);
	int value = __sync_fetch_and_add(&count, 1);
	assert(value == 0 && "causality violation");

	ERR(thr_join(tid, NULL));

	return 0;
}
コード例 #18
0
ファイル: zfd.c プロジェクト: arekinath/illumos-joyent
void
destroy_log_thread()
{
	if (logger_tid != 0) {
		int stop = 1;

		shutting_down = 1;
		/* break out of poll to shutdown */
		if (eventstream[0] != -1)
			(void) write(eventstream[0], &stop, sizeof (stop));
		(void) thr_join(logger_tid, NULL, NULL);
		logger_tid = 0;
	}

	(void) destroy_zfd_devs(zlogp);
}
コード例 #19
0
ファイル: many_thr.c プロジェクト: jindal25/Coding4cpp
main(int argc, char **argv)
{
int i, thr_count = 100;
char buf;

/* check to see if user passed an argument
   -- if so, set the number of threads to the value
      passed to the program */

if (argc == 2) thr_count = atoi(argv[1]);

printf("Creating %d threads...\n", thr_count);

/* lock the mutex variable -- this mutex is being used to 
   keep all the other threads created from proceeding   */

mutex_lock(&lock);

/* create all the threads -- Note that a specific stack size is
   given.  Since the created threads will not use all of the
   default stack size, we can save memory by reducing the threads'
   stack size */

for (i=0;i<thr_count;i++) {
	thr_create(NULL,2048,thr_sub,0,0,NULL);
	}

printf("%d threads have been created and are running!\n", i);
printf("Press <return> to join all the threads...\n", i);

/* wait till user presses return, then join all the threads */
gets(&buf);

printf("Joining %d threads...\n", thr_count);

/* now unlock the mutex variable, to let all the threads proceed */
mutex_unlock(&lock);

/* join the threads */
for (i=0;i<thr_count;i++) 
	thr_join(0,0,0);

printf("All %d threads have been joined, exiting...\n", thr_count);
return(0);
}
コード例 #20
0
ファイル: htm_deadlock.c プロジェクト: bblum/landslide
int main(void)
{
	report_start(START_CMPLT);

	ERR(thr_init(4096));
	ERR(mutex_init(&lock));
	misbehave(BGND_BRWN >> FGND_CYAN); // for landslide

	int tid = thr_create(child, NULL);
	ERR(tid);

	txn();
	ERR(thr_join(tid, NULL));
	assert(count == 2);


	return 0;
}
コード例 #21
0
ファイル: testpw6.c プロジェクト: Distrotech/nss_ldap
void
main (int argc, char **argv)
{
#ifdef _REENTRANT
  int i;
#ifdef HAVE_PTHREAD_H
  pthread_t tids[MAX_THREADS];
#endif
#endif
  pid_t pid;
  ARGC = argc;
  ARGV = argv;

  /* PRIME */
  scan_passwd();

   pid = fork();
   if (pid == 0) {
	printf("IN CHILD\n");
   } else {
	printf("IN PARENT\n");
   }

#ifdef _REENTRANT
  for (i = 0; i < MAX_THREADS; i++)
    {
#ifdef HAVE_PTHREAD_H
      pthread_create(&tids[i], NULL, test_passwd, NULL);
#else
      thread_t tid;
      thr_create (NULL, 0, test_passwd, NULL, 0, &tid);
      thr_continue (tid);
#endif /* HAVE_PTHREAD_H */
    }
#ifdef HAVE_PTHREAD_H
  for (i = 0; i < MAX_THREADS; i++) pthread_join(tids[i], NULL);
#else
  while (thr_join (NULL, NULL, NULL) == 0);
#endif
#else
  test_passwd ();
#endif
  exit (0);
}
コード例 #22
0
int main(int argc,char* argv[])
{
	if(argv[2]==NULL)
	{
		printf("Please enter value of num_Empty!!!\n");
		return 1;
	}
	if(argv[1]==NULL)
	{	
		printf("Please enter File Name!!!\n");
		return 1;
	}
	EMPTY=atoi(argv[2]);
	int readInputFile(char *);
	int displaynetwork();	
	int sendMessage(int ,int ,int ,int );
	int enterQueue(struct Message *,int );
	int displayMessage(struct Message *);
	int checkQueue();	
	struct Message* getMessage(int);
	int initializeQueues();
	int broadcastMessage();
	logFile=fopen("stage7_log","w");
	int statusRead=readInputFile(argv[1]);
	if(statusRead==0)
		displaynetwork();	
	printf("\n");
	//creating totalPeers thread
	int i,status;
	for (i=2; i<totalPeers+2; i++)
 		 thr_create(NULL, 0, peer, (void*)i, THR_BOUND, &thr[i]);
	printf("\n");	
	broadcastMessage();
	//wait for all threads to finish
	while (thr_join(0, &tid, (void**)&status)==0)
  		printf("\n[Status of thread Id %d is=%d]", tid,status);

	
	checkQueue();	
	fclose(logFile);
	fclose(fp);
	return 0;
}
コード例 #23
0
ファイル: java_md.c プロジェクト: cncomkyle/openjdk_7_b147
/*
 * Block current thread and continue execution in a new thread
 */
int
ContinueInNewThread0(int (JNICALL *continuation)(void *), jlong stack_size, void * args) {
    int rslt;
#ifdef __linux__
    pthread_t tid;
    pthread_attr_t attr;
    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);

    if (stack_size > 0) {
      pthread_attr_setstacksize(&attr, stack_size);
    }

    if (pthread_create(&tid, &attr, (void *(*)(void*))continuation, (void*)args) == 0) {
      void * tmp;
      pthread_join(tid, &tmp);
      rslt = (int)tmp;
    } else {
     /*
      * Continue execution in current thread if for some reason (e.g. out of
      * memory/LWP)  a new thread can't be created. This will likely fail
      * later in continuation as JNI_CreateJavaVM needs to create quite a
      * few new threads, anyway, just give it a try..
      */
      rslt = continuation(args);
    }

    pthread_attr_destroy(&attr);
#else
    thread_t tid;
    long flags = 0;
    if (thr_create(NULL, stack_size, (void *(*)(void *))continuation, args, flags, &tid) == 0) {
      void * tmp;
      thr_join(tid, NULL, &tmp);
      rslt = (int)tmp;
    } else {
      /* See above. Continue in current thread if thr_create() failed */
      rslt = continuation(args);
    }
#endif
    return rslt;
}
コード例 #24
0
ファイル: sh6bench.c プロジェクト: cksystemsgroup/libscm
/* wait for all benchmark threads to terminate */
void WaitForThreads(ThreadID tids[], unsigned tidCnt)
{
#ifdef __OS2__
	while (tidCnt--)
		DosWaitThread(&tids[tidCnt], DCWW_WAIT);

#elif defined(WIN32)
	WaitForMultipleObjects(tidCnt, tids, TRUE, INFINITE);

#elif defined(__sun)
	int prio;
	thr_getprio(thr_self(), &prio);
	thr_setprio(thr_self(), max(0, prio-1));
	while (tidCnt--)
		thr_join(0, NULL, NULL);

#elif defined(_POSIX_THREADS) || defined(_POSIX_REENTRANT_FUNCTIONS)
	while (tidCnt--)
		pthread_join(tids[tidCnt], NULL);

#endif
}
コード例 #25
0
ファイル: attach.c プロジェクト: Andrel322/gecko-dev
int main(int argc, char **argv)
{
#ifdef _PR_PTHREADS
    int rv;
    pthread_t threadID;
    pthread_attr_t attr;
#elif defined(SOLARIS)
    int rv;
    thread_t threadID;
#elif defined(WIN32)
    DWORD rv;
    unsigned threadID;
    HANDLE hThread;
#elif defined(IRIX)
    int rv;
    int threadID;
#elif defined(OS2)
    int rv;
    TID threadID;
#elif defined(XP_BEOS)
	thread_id threadID;
	int32 threadRV;
	status_t waitRV;
#endif

	/* 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] [-c n]
	*/
	PLOptStatus os;
	PLOptState *opt = PL_CreateOptState(argc, argv, "dc:");
	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;
        case 'c':  /* loop count */
			count = atoi(opt->value);
            break;
         default:
            break;
        }
    }
	PL_DestroyOptState(opt);

#if defined(WIN16)
    printf("attach: This test is not valid for Win16\n");
    goto exit_now;
#endif

	if(0 == count) count = DEFAULT_COUNT;	

    /*
     * To force the implicit initialization of nspr20
     */
    PR_SetError(0, 0);
    PR_STDIO_INIT();

    /*
     * Platform-specific code to create a native thread.  The native
     * thread will repeatedly call PR_AttachThread and PR_DetachThread.
     * The primordial thread waits for this new thread to finish.
     */

#ifdef _PR_PTHREADS

    rv = _PT_PTHREAD_ATTR_INIT(&attr);
    if (debug_mode) PR_ASSERT(0 == rv);
	else if (0 != rv) {
		failed_already=1;
		goto exit_now;
	}
	
#ifndef _PR_DCETHREADS
    rv = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
    if (debug_mode) PR_ASSERT(0 == rv);
	else if (0 != rv) {
		failed_already=1;
		goto exit_now;
	}
#endif  /* !_PR_DCETHREADS */
    rv = _PT_PTHREAD_CREATE(&threadID, attr, threadStartFunc, NULL);
    if (rv != 0) {
			fprintf(stderr, "thread creation failed: error code %d\n", rv);
			failed_already=1;
			goto exit_now;
	}
	else {
		if (debug_mode)
			printf ("thread creation succeeded \n");

	}
    rv = _PT_PTHREAD_ATTR_DESTROY(&attr);
    if (debug_mode) PR_ASSERT(0 == rv);
	else if (0 != rv) {
		failed_already=1;
		goto exit_now;
	}
    rv = pthread_join(threadID, NULL);
    if (debug_mode) PR_ASSERT(0 == rv);
	else if (0 != rv) {
		failed_already=1;
		goto exit_now;
	}

#elif defined(SOLARIS)

    rv = thr_create(NULL, 0, threadStartFunc, NULL, 0, &threadID);
    if (rv != 0) {
	if(!debug_mode) {
		failed_already=1;
		goto exit_now;
	} else	
		fprintf(stderr, "thread creation failed: error code %d\n", rv);
    }
    rv = thr_join(threadID, NULL, NULL);
    if (debug_mode) PR_ASSERT(0 == rv);
	else if (0 != rv)
	{
		failed_already=1;
		goto exit_now;
	}


#elif defined(WIN32)

    hThread = (HANDLE) _beginthreadex(NULL, 0, threadStartFunc, NULL,
            STACK_SIZE_PARAM_IS_A_RESERVATION, &threadID);
    if (hThread == 0) {
        fprintf(stderr, "thread creation failed: error code %d\n",
                GetLastError());
		failed_already=1;
		goto exit_now;
    }
    rv = WaitForSingleObject(hThread, INFINITE);
    if (debug_mode)PR_ASSERT(rv != WAIT_FAILED);
	else if (rv == WAIT_FAILED) {
		failed_already=1;
		goto exit_now;
	}

#elif defined(IRIX)

    threadID = sproc(threadStartFunc, PR_SALL, NULL);
    if (threadID == -1) {

			fprintf(stderr, "thread creation failed: error code %d\n",
					errno);
			failed_already=1;
			goto exit_now;
	
	}
	else {
		if (debug_mode) 
			printf ("thread creation succeeded \n");
		sleep(3);
		goto exit_now;
	}
    rv = waitpid(threadID, NULL, 0);
    if (debug_mode) PR_ASSERT(rv != -1);
	else  if (rv != -1) {
		failed_already=1;
		goto exit_now;
	}

#elif defined(OS2)

    threadID = (TID) _beginthread((void *)threadStartFunc, NULL,
            32768, NULL); 
    if (threadID == -1) {
        fprintf(stderr, "thread creation failed: error code %d\n", errno);
        failed_already=1;
        goto exit_now;
    }
    rv = DosWaitThread(&threadID, DCWW_WAIT);
    if (debug_mode) {
        PR_ASSERT(rv == NO_ERROR);
    } else if (rv != NO_ERROR) {
        failed_already=1;
        goto exit_now;
    }

#elif defined(XP_BEOS)
	
	threadID = spawn_thread(threadStartFunc, NULL, B_NORMAL_PRIORITY, NULL);
	if (threadID <= B_ERROR) {
		fprintf(stderr, "thread creation failed: error code %08lx\n", threadID);
		failed_already = 1;
		goto exit_now;
	}
	if (resume_thread(threadID) != B_OK) {
		fprintf(stderr, "failed starting thread: error code %08lx\n", threadID);
		failed_already = 1;
		goto exit_now;
	}

	waitRV = wait_for_thread(threadID, &threadRV);
	if (debug_mode)
		PR_ASSERT(waitRV == B_OK);
	else if (waitRV != B_OK) {
		failed_already = 1;
		goto exit_now;
	}
	
#else
	if (!debug_mode)
		failed_already=1;
	else	
		printf("The attach test does not apply to this platform because\n"
	    "either this platform does not have native threads or the\n"
	    "test needs to be written for this platform.\n");
	goto exit_now;
#endif

exit_now:
   if(failed_already)	
		return 1;
	else
		return 0;
}
コード例 #26
0
ファイル: thr_thr.c プロジェクト: 1ack/Impala
int ldap_pvt_thread_join( ldap_pvt_thread_t thread, void **thread_return )
{
	thr_join( thread, NULL, thread_return );
	return 0;
}
コード例 #27
0
ファイル: ypserv_proc.c プロジェクト: andreiw/polaris
/*
 * This implements the "get all" function.
 */
void
ypall(SVCXPRT *transp)
{
	struct ypreq_nokey req;
	struct ypresp_val resp;  /* not returned to the caller */
	pid_t pid;
	char *fun = "ypall";
	DBM *fdb;

	req.domain = req.map = NULL;

	memset((char *)&req, 0, sizeof (req));

	if (!svc_getargs(transp,
				(xdrproc_t)xdr_ypreq_nokey,
				(char *)&req)) {
		svcerr_decode(transp);
		return;
	}

	pid = fork1();

	if (pid) {

		if (pid == -1) {
			FORK_ERR;
		}

		if (!svc_freeargs(transp,
					(xdrproc_t)xdr_ypreq_nokey,
					(char *)&req)) {
			FREE_ERR;
		}

		return;
	}

	/*
	 * access control hack:  If denied then invalidate the map name.
	 */
	ypclr_current_map();
	if ((fdb = ypset_current_map(req.map,
		req.domain, &resp.status)) != NULL &&
		!yp_map_access(transp, &resp.status, fdb)) {

		req.map[0] = '-';
	}

	/*
	 * This is the child process.  The work gets done by xdrypserv_ypall/
	 * we must clear the "current map" first so that we do not
	 * share a seek pointer with the parent server.
	 */

	if (!svc_sendreply(transp,
				(xdrproc_t)xdrypserv_ypall,
				(char *)&req)) {
		RESPOND_ERR;
	}

	if (!svc_freeargs(transp,
				(xdrproc_t)xdr_ypreq_nokey,
				(char *)&req)) {
		FREE_ERR;
	}

	/*
	 * In yptol mode we may start a cache update thread within a child
	 * process. It is thus important that child processes do not exit,
	 * killing any such threads, before the thread has completed.
	 */
	if (yptol_mode) {
		thr_join(0, NULL, NULL);
	}

	exit(0);
}
コード例 #28
0
ファイル: ptester.c プロジェクト: as2120/ZAchieve
int main(int argc,
         char *argv[])
{
    int i, j, t;
    int n_tids = 0;
    thread_t tid[256];
    time_t start_time, stop_time;


    signal(SIGPIPE, SIG_IGN);

    for (i = 1; i < argc && argv[i][0] == '-'; i++)
        switch (argv[i][1])
        {
        case '?':
        case 'H':
            exit(help(argv[0]));
            break;

        case 'd':
            debug = atoi(argv[i]+2);
            break;

        case 'R':
            rcvbuf_size = atoi(argv[i]+2);
            break;

        case 't':
            test_length = atoi(argv[i]+2);
            break;

        case 'h':
            server_host = argv[i]+2;
            break;

        case 'p':
            server_port = argv[i]+2;
            break;

        case 'b':
            if (isdigit(argv[i][2]))
                bound_threads = atoi(argv[i]+2);
            else
                bound_threads = 1;
            break;

        case 'c':
            concurrency = atoi(argv[i]+2);
            break;

        case 'E':
            use_exit = 1;
            break;

        case 'e':
            expected_bytes = atoi(argv[i]+2);
            break;

        case 'r':
            repeat = atoi(argv[i]+2);
            break;

        case 'k':
            keepalive = atoi(argv[i]+2);
            break;

        case '0':
            http_0 = 1;
            break;

        default:
            fprintf(stderr, "%s: unknown switch '%s', try -H for help\n",
                    argv[0], argv[1]);
            exit(1);
        }

    keepalive++;

    mutex_init(&result_lock, USYNC_THREAD, NULL);

    if (mksockaddr_in(server_host, server_port, &server_addr) < 0)
    {
        fprintf(stderr, "Error creating socket address\n");
        exit(1);
    }

    fprintf(stderr, "Running test: ");

    for (t = 0; t < test_length; t++)
    {
        if (t % 10)
            putc('-', stderr);
        else
            putc('+', stderr);
    }

    fprintf(stderr, "\rRunning test: ");

    if (concurrency > 0)
        thr_setconcurrency(concurrency);

    time(&start_time);

    for (; i < argc; i++)
    {
        for (j = 0; j < repeat; j++)
        {
            if (thr_create(NULL,
                           0,
                           (void *(*)(void *)) test_thread,
                           (void *) argv[i],
                           (bound_threads ? THR_BOUND : 0) +
                           THR_NEW_LWP,
                           &tid[n_tids]))
            {
                perror("thr_create");
                exit(1);
            }

            n_tids++;
        }
    }

    for (t = 0; t < test_length; t++)
    {
        xsleep(1);
        putc('>', stderr);
        fflush(stdout);
    }

    putc('\n', stderr);
    putc('\n', stderr);

    printf("%-19s %4s  %6s %6s %6s  %6s %6s %6s  %s\n",
           "URL",
           "NRq",
           "Min Ct",
           "Avg Ct",
           "Max Ct",
           "Min Tx",
           "Avg Tx",
           "Max Tx",
           "Bytes");

    stop_flag = 1;

    for (i = 0; i < n_tids; i++)
        thr_join(tid[i], NULL, NULL);

    if (failure)
        exit(1);

    time(&stop_time);

    test_length = (int) stop_time - (int) start_time;

    putchar('\n');

    printf("Actual test time.. %d seconds\n", test_length);

    printf("Total requests.... %d (%d requests/sec)\n",
           total_nrq,
           total_nrq / test_length);

    printf("Total failed...... %d (%d requests/sec)\n",
           total_failed,
           total_failed / test_length);

    printf("Total bytes....... %d (%d bytes/sec)\n",
           total_bytes,
           total_bytes / test_length);

    putchar('\n');
    printf("Min Tx: %.4f\n", min_tx);
    printf("Max Tx: %.4f\n", max_tx);

    exit(0);
}
コード例 #29
0
ファイル: dev_rmscsi.c プロジェクト: andreiw/polaris
/*
 * XXX: a bug still exists here.  we have a thread polling on this
 * XXX: device in the kernel, we need to get rid of this also.
 * XXX: since we're going to move the waiter thread up to the
 * XXX: user level, it'll be easier to kill off as part of the
 * XXX: cleanup of the device private data.
 */
static void
rmscsi_close(char *path, dev_t rdev)
{
	char			namebuf[MAXNAMELEN];
	struct	stat		sb;
	struct devs		*dp;
	struct rmscsi_priv	*rsp;
	int			i;

	debug(1, "rmscsi_close %s\n", path);

	(void) sprintf(namebuf, RMSCSI_NAMEPROTO, path, RMSCSI_BASEPART);
	if (stat(namebuf, &sb) < 0) {
		if (rdev == NODEV) {
			warning(gettext("rmscsi_close: %s; %m\n"), namebuf);
			return;
		}
	} else {
		rdev = sb.st_rdev;
	}

	if ((dp = dev_getdp(rdev)) == NULL) {
		debug(1, "rmscsi_close: %s not in use\n", path);
		return;
	}

	/* get our private data */
	rsp = (struct rmscsi_priv *)dp->dp_priv;

	/*
	 * take care of the listner thread
	 */
	(void) mutex_lock(&rsp->rs_killmutex);
	(void) thr_kill(rsp->rs_tid, SIGUSR1);
	(void) mutex_unlock(&rsp->rs_killmutex);
	(void) thr_join(rsp->rs_tid, 0, 0);
	debug(1, "rmscsi_close: thread id %d reaped (killed/joined)\n",
	    rsp->rs_tid);

	/*
	 * if there is a volume inserted in this device ...
	 */
	if (dp->dp_vol) {
		/*
		 * clean up the name space and the device maps
		 * to remove references to any volume that might
		 * be in the device right now
		 *
		 * this crap with the flags is to keep the
		 * "poll" from being relaunched by this function
		 *
		 * yes, its a hack and there should be a better way
		 */
		if (dp->dp_dsw->d_flags & D_POLL) {
			dp->dp_dsw->d_flags &= ~D_POLL;
			dev_eject(dp->dp_vol, TRUE);
			dp->dp_dsw->d_flags |= D_POLL;
		} else {
			dev_eject(dp->dp_vol, TRUE);
		}
		if (dp->dp_vol != NULL) {
			return;
		}
		/* do the eject work */
		(void) ioctl(rsp->rs_fd[RMSCSI_BASEPART], DKIOCEJECT, 0);
	}

	/*
	 * clean up the names in the name space
	 */
	node_unlink(dp->dp_bvn);
	node_unlink(dp->dp_rvn);

	/*
	 * free the private data we've allocated
	 */
	for (i = 0; i < V_NUMPAR; i++) {
		if (rsp->rs_rawpath[i]) {
			free(rsp->rs_rawpath[i]);
		}
		if (rsp->rs_fd[i] != -1) {
			(void) close(rsp->rs_fd[i]);
		}
	}
#if defined(_FIRMWARE_NEEDS_FDISK)
	for (i = 0; i < (FD_NUMPART+1); i++) {
		if (rsp->rs_raw_pfd[i] >= 0) {
			(void) close(rsp->rs_raw_pfd[i]);
		}
	}
#endif
	free(rsp);

	/*
	 * free the dp, so no one points at us anymore
	 */
	dev_freedp(dp);
}
コード例 #30
0
ファイル: wclient.c プロジェクト: JudsonWilson/mctls
// Read file line by line with timing information 
static void *browser_replay(void *ptr){
	char line[300];
	//int previous_time = 0;      // current/previous time
	FILE *fp;                   // pointer to file
	int curr_line = 0;       // keep track of line read 

	#ifdef DEBUG
	printf("[DEBUG] Read file timing\n"); 
	#endif 

	// Retrive filename from (void *)
	char *file_name = (char *)ptr;    

	// Open file for reading
    fp = fopen(file_name,"r");  
   
    // Check for errors while opening file
    if( fp == NULL ){
        printf("Error while opening file %s.\r\n", file_name);
        return NULL; 
    }
	
    // Read file line-by-line
    while ( fgets ( line, sizeof line, fp ) != NULL &&  curr_line < lines) {
		double time;
		//double duration; 
		char file_request[128]; 
	
		// Current line read in the file
		curr_line ++; 
		
		// Remove trailing newline (NOTE: strtoK is not thread safe)
        strtok(line, "\n");

		#ifdef DEBUG
		printf("[DEBUG] Read line is <<%s>>\n", line);
		#endif 

		// Parse line
		//sscanf(line, "%lf %lf", &time, &duration); 
		sscanf(line, "%lf %s", &time, file_request); 
		
		// Logging 
		#ifdef DEBUG
		//printf("[DEBUG] Extracted values are: %f -- %f\n", time, duration);
		printf("[DEBUG] Extracted values are: %f -- %s\n", time, file_request);
		#endif

		/* Original code to relay timing information from traces
		// Compute sleeping time 
		double time_to_sleep = time - previous_time; 
		#ifdef DEBUG
		printf("[DEBUG] Sleeping for %f\n", time_to_sleep); 
		#endif 
    	sleep(time_to_sleep);
	
		*/ 

		// Send HTTP GET 
		#ifdef DEBUG
		printf("[DEBUG] Sending GET request for <<%s>> bytes of data\n", file_request); 
		#endif 
		
		if (curr_line == lines){
			#ifdef DEBUG
			printf("[DEBUG] File has %d GET and we sent %d. Reading thread is done\n", lines, curr_line); 
			#endif 
			running = false; 
		}
		sendRequestBrowser(file_request); 
		// Wait on main thread to have received requested data unless we are done 
		if (curr_line < lines){
			#ifdef DEBUG
			printf("[DEBUG] Wait on main thread"); 
			#endif 
			thr_join(); 
		}
		done = 0;  
		
		/* Not used 
		// Save current time
		previous_time = time;  
		*/
	}

	#ifdef DEBUG
	printf("[DEBUG] Closing file\n"); 
	#endif 
    
	// Close file
    fclose(fp);
	
	// All good 
	return NULL;  
}