static void tester(long a0, void *a1) { int i = 0, ret; char pbuffer[SBUFSZ]; while (i < 10) { sprintf(pbuffer, "thread %i: hello! (%i)\n", uthread_self(), i++); ret = write(STDOUT_FILENO, pbuffer, strlen(pbuffer)); if (ret < 0) { perror("uthreads_test"); /* XXX: we should really cleanup here */ exit(1); } uthread_mtx_lock(&mtx); uthread_cond_signal(&cond); uthread_cond_wait(&cond, &mtx); uthread_mtx_unlock(&mtx); } sprintf(pbuffer, "thread %i exiting.\n", uthread_self()); ret = write(STDOUT_FILENO, pbuffer, strlen(pbuffer)); if (ret < 0) { perror("uthreads_test"); /* XXX: we should really cleanup here */ exit(1); } uthread_exit(a0); }
void blockUntilComplete() { // TODO queue_enqueue(&prq,uthread_self()); uthread_block(); //block the thread while it is reading }
void foo(void* sem) { int k; binary_semaphore_down((struct binary_semaphore*)sem); for (k=0; k<20; k++) { printf (1, "foo: tid: %d\n", uthread_self()); } binary_semaphore_up((struct binary_semaphore*)sem); }
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(); }
void * thread( void * arg ) { int cnt = 0 ; while (cnt < 10000000) { //sleep(1); if ( cnt % 1000000 == 0 ) printf("hello, i am child thread named %d call for the %d times.\n",uthread_self(),cnt); //uthread_yield(); cnt ++ ; //if ( cnt == 3 ) uthread_exit(); } return NULL ; }