void* parent(void* n)
{	
	int i = *(int*)n;

	printf("--Entered parent thread--\n");

	int m = 2 * i;

	int child_id = uthread_create(proc3, &m);

	if(id3 != -1)
	{
		printf("--Created child thread--\n");
	}
	else
	{
		printf("--Creation of child thread failed--\n");
	}

	for(; i > 0; i--)
	{
		printf("Parent: %d\n", i);
		uthread_yield();
	}

	return NULL;
}
Ejemplo n.º 2
0
int
main ()
{
  int i = 0;

  uthread_init ();

  uthread_create (threadFunc, 1, 0);
  uthread_create (threadFunc, 2, 0);
  uthread_create (threadFunc, 3, 0);
  uthread_create (threadFunc, 4, 0);
  //uthread_create (threadFunc, 5, 5);
  //uthread_create (threadFunc, 6, 3);
  //uthread_create (threadFunc, 7, 3);
  //uthread_create (threadFunc, 8, 2);

  // uncomment to test uthread_exit() on main earlier than others
  //uthread_exit();

  while( 1 ) printf("Waiting for interrupt.\n");

  for (i = 0; i < 10; i++)
    {
      printf ("This is the main function\n");
      uthread_yield ();
    }
  printf ("I am main and I am exiting\n");

  uthread_exit ();

  printf ("You shall not reach this line\n");
  return 0;
}
Ejemplo n.º 3
0
void func2(void * arg)
{
    puts("22");
    puts("22");
    uthread_yield(*(schedule_t *)arg);
    puts("22");
    puts("22");
}
Ejemplo n.º 4
0
void* ping (void* x) {
  int i,j;
  for (i=0; i<NUM_ITERATIONS; i++) {
    printf ("I");
    for (j=0; j<10000; j++) {}
  uthread_yield();
  }
}
Ejemplo n.º 5
0
static void *run_vm(void *arg)
{
	struct vmctl *vmctl = (struct vmctl*)arg;

	assert(vmctl->command == REG_RSP_RIP_CR3);
	/* We need to hack our context, so that next time we run, we're a VM ctx */
	uthread_yield(FALSE, __build_vm_ctx_cb, arg);
}
Ejemplo n.º 6
0
void func3(void *arg)
{
    puts("3333");
    puts("3333");
    uthread_yield(*(schedule_t *)arg);
    puts("3333");
    puts("3333");

}
Ejemplo n.º 7
0
/* Run a specific sighandler from the top of the sigdata stack. The 'info'
 * struct is prepopulated before the call is triggered as the result of a
 * reflected fault. */
static void __run_sighandler()
{
	struct pthread_tcb *me = pthread_self();
	__sigdelset(&me->sigpending, me->sigdata->info.si_signo);
	trigger_posix_signal(me->sigdata->info.si_signo,
	                     &me->sigdata->info,
	                     &me->sigdata->u_ctx);
	uthread_yield(FALSE, __exit_sighandler_cb, 0);
}
Ejemplo n.º 8
0
void sanityMethod(){
	int i;
	uthread_t t = uthread_self();
	for (i = 0; i<numOfIterations; i++){
		printf(2, "thread %d iteration %d\n",t.tid, i);
		uthread_yield();
	}
	printf(3, "killing %d, with %d and %d iters", t.tid, t.priority, numOfIterations);
	uthread_exit();
}
Ejemplo n.º 9
0
void *func2(void *arg)
{
    int *ti=(int*)arg;
    printf("func2: started\n");
    printf("func2: %d\n",*(int*)arg);
    for ( ; *ti<10; (*ti)++) {
	printf ("func2 i = %d \n",*ti);
        uthread_yield();
    }
    printf("func2: %d - returning\n",*(int*)arg);
    return NULL;
}
Ejemplo n.º 10
0
int main(int argc, char **argv) {
  printf("Testing uthread_create\n");
	    
  uthread_init();
    
  uthread_create(thread_start, 1, 0); 
      
  uthread_yield();
  printf("back in main\n");
  uthread_exit();
  return 0;
}
Ejemplo n.º 11
0
/* Run through all pending sighandlers and trigger them with a NULL info field.
 * These handlers are triggered as the result of a pthread_kill(), and thus
 * don't require individual 'info' structs. */
static void __run_pending_sighandlers()
{
	struct pthread_tcb *me = pthread_self();
	sigset_t andset = me->sigpending & (~me->sigmask);
	for (int i = 1; i < _NSIG; i++) {
		if (__sigismember(&andset, i)) {
			__sigdelset(&me->sigpending, i);
			trigger_posix_signal(i, NULL, &me->sigdata->u_ctx);
		}
	}
	uthread_yield(FALSE, __exit_sighandler_cb, 0);
}
void* child(void* n)
{
	int i = *(int*)n;

	printf("--Entered child thread--\n");

	for(; i > 0; i--)
	{
		printf("Child: %d\n", i);
		uthread_yield();
	}

	return NULL;
}
Ejemplo n.º 13
0
int upthread_cond_wait(upthread_cond_t *c, upthread_mutex_t *m)
{
	if(c == NULL)
		return EINVAL;
	if(m == NULL)
		return EINVAL;

	mcs_lock_qnode_t qnode = {0};
	mcs_pdr_lock(&c->lock, &qnode);
	c->waiting_mutex = m;
	c->waiting_qnode = &qnode;
	uthread_yield(true, block, c);
	return upthread_mutex_lock(m);
}
Ejemplo n.º 14
0
void *func1(void *arg)
{
    int *ti=(int*)arg;
    printf("func1: started\n");
    printf("func1: %d\n",*(int*)arg);
    
    //Testando comunicacao entre threads, atraves da variavel i
    for ( ; *ti<10; (*ti)++) {
	printf ("func1 i = %d\n",*ti);
        uthread_yield();
    }

    printf("func1: %d - returning\n",*(int*)arg);
    return NULL;
}
Ejemplo n.º 15
0
static inline int futex_wait(int *uaddr, int val, uint64_t ms_timeout)
{
  // Atomically do the following...
  mcs_pdr_lock(&__futex.lock);
  // If the value of *uaddr matches val
  if(*uaddr == val) {
    // Create a new futex element and initialize it.
    struct futex_element e;
    bool enable_timer = false;
    e.uaddr = uaddr;
    e.pthread = NULL;
    e.ms_timeout = ms_timeout;
    e.timedout = false;
    if(e.ms_timeout != (uint64_t)-1) {
      e.ms_timeout += __futex.time;
	  // If we are setting the timeout, get ready to
	  // enable the timer if it is currently disabled.
      if(__futex.timer_enabled == false) {
        __futex.timer_enabled = true;
        enable_timer = true;
      }
    }
    // Insert the futex element into the queue
    TAILQ_INSERT_TAIL(&__futex.queue, &e, link);
    mcs_pdr_unlock(&__futex.lock);

    // Enable the timer if we need to outside the lock
    if(enable_timer)
      futex_wake(&__futex.timer_enabled, 1);

    // Yield the current uthread
    uthread_yield(TRUE, __futex_block, &e);

	// After waking, if we timed out, set the error
	// code appropriately and return
    if(e.timedout) {
      errno = ETIMEDOUT;
      return -1;
    }
  }
  else {
    mcs_pdr_unlock(&__futex.lock);
  }
  return 0;
}
Ejemplo n.º 16
0
void* proc1(void* n)
{
	int i = *(int*)n;

	printf("--Hello from proc1--\n");

	for(; i > 0; i--)
	{
		printf("i=%d\n", i);

		if(i % 5 == 0)
		{
			uthread_yield();
		}
	}

	return NULL;
}
Ejemplo n.º 17
0
void do_something()
{
    int id;

    id=myid;
    myid++;

    printf("This is ult %d\n", id);
    if(n_threads<10){
        uthread_create(do_something,2);
        n_threads++;
        uthread_create(do_something,2);
        n_threads++;
    }
    printf("This is ult %d again\n",id);
    uthread_yield(1);
    printf("This is ult %d once more\n",id);
	uthread_exit();
}
Ejemplo n.º 18
0
/* Lame user thread */
void
threadFunc (int val)
{
  int i, j;

  //if( val%2 == 0 ) uthread_exit();

  for (i = 0; i < 5; i++)
    {
      printf ("Thread: %d Count: %d\n", val, i);
      for(j=0;j<10000000;j++)
        {
          if( j%1000000 == 0 ) printf("%i*", val);
        }
      printf("\n");
      uthread_yield ();
    }
  uthread_exit ();
}
Ejemplo n.º 19
0
int upthread_mutex_lock(upthread_mutex_t* mutex)
{
	if(mutex == NULL)
		return EINVAL;

	spin_pdr_lock(&mutex->lock);
	if(mutex->attr.type == UPTHREAD_MUTEX_RECURSIVE &&
		mutex->owner == upthread_self()) {
		mutex->locked++;
	}
	else {
		while(mutex->locked) {
			uthread_yield(true, block, mutex);

			spin_pdr_lock(&mutex->lock);
		}
		mutex->owner = upthread_self();
		mutex->locked++;
	}
	spin_pdr_unlock(&mutex->lock);
	return 0;
}
Ejemplo n.º 20
0
void do_something()
{
  int id;
  id = myid;
  myid++;
  printf("This is ult %d\n", id); //just for demo purpose

  if(n_threads < 5){
    uthread_create(do_something);
    n_threads++;
    printf("ult %d yields \n",id );
    uthread_yield();
    printf("ult %d resumes \n",id);
    uthread_create(do_something);
    n_threads++;
  }

  printf("ult %d starts I/O \n",id);
  uthread_startIO();
  sleep(2); //simulate some long−time I/O operation
  uthread_endIO();
  printf("ult %d returns from I/O \n",id);
  uthread_exit();
}
Ejemplo n.º 21
0
void thread_start(int val) {
  printf("In thread_start %d , control transfered\n", val);
  uthread_yield();
}
Ejemplo n.º 22
0
int pthread_yield(void)
{
	uthread_yield();
	return 0;
}
Ejemplo n.º 23
0
static void pth_switch_to(struct pthread_tcb *target)
{
	uthread_yield(TRUE, __pth_switch_cb, target);
}
Ejemplo n.º 24
0
void uthread_sleep(void)
{
    threadTable.runningThread->state = T_SLEEPING;
    uthread_yield();
}