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; }
int main() { system_init(); uthread_create(do_something,2); uthread_exit(); return 0; }
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* thread(void *arg) { long tmp; tmp = (long) arg; tmp += 1; uthread_exit((void *) tmp); }
static void thread_start(void (*func)(), long arg1, void *arg2) { assert(func != NULL); (func)(arg1, arg2); /* the thread exited */ uthread_exit(0); }
int main() { int i; system_init(); uthread_create(do_something); uthread_exit(); // sleep(5); return 0; }
int main(int ac, char **av) { int i; uthread_init(); uthread_mtx_init(&mtx1); uthread_mtx_init(&mtx2); uthread_mtx_init(&mtx3); uthread_cond_init(&cond); void (*tester[3]) (long a0, void* a1); tester[0] = tester1; tester[1] = tester2; tester[2] = tester3; for (i = 0; i < NUM_THREADS; i++) { uthread_create(&thr[i], tester[i], i, NULL, UTH_MAXPRIO - i % UTH_MAXPRIO //2 ); } //uthread_setprio(thr[0], 6); for (i = 0; i < NUM_THREADS; i++) { char pbuffer[SBUFSZ]; int tmp, ret; uthread_join(thr[i], &tmp); sprintf(pbuffer, "joined with thread %i, exited %i.\n", thr[i], tmp); ret = write(STDOUT_FILENO, pbuffer, strlen(pbuffer)); if (ret < 0) { perror("uthreads_test"); return EXIT_FAILURE; } /* uthread_mtx_lock(&mtx); uthread_cond_signal(&cond); uthread_mtx_unlock(&mtx); */ } printf("Main ends\n"); uthread_exit(0); return 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(); }
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; }
int main(int argc, char *argv[]) { uthread_init(); int stam = 10; int stam1 = 12; int stam2 = 20; uthread_create(tester,&stam); uthread_create(tester,&stam1); uthread_create(tester,&stam2); uthread_exit(); return 0; }
int uthread_cancel(thread_id th) { thread_t *thread; uthread_disable(); if(current->id == th) { uthread_exit(UTHREAD_CANCELLED); } thread = uthread_find(th); if(thread == NULL) return UTHREAD_INVALID; uthread_notify_exit(thread, UTHREAD_CANCELLED); if(thread->state != THREAD_ZOMBIE) uthread_free(thread); return UTHREAD_SUCCESS; }
int main(int ac, char **av) { int i; /* char buff[50]; memset(buff,0,50); sprintf(buff, "helloworld\n"); write(STDOUT_FILENO, buff, strlen(buff)); */ printf("hello\n"); uthread_init(); uthread_mtx_init(&mtx); uthread_cond_init(&cond); for (i = 0; i < NUM_THREADS; i++) { uthread_create(&thr[i], tester, i, NULL, 0); } uthread_setprio(thr[0], 2); for (i = 0; i < NUM_THREADS; i++) { char pbuffer[SBUFSZ]; int tmp, ret; uthread_join(thr[i], &tmp); sprintf(pbuffer, "joined with thread %i, exited %i.\n", thr[i], tmp); ret = write(STDOUT_FILENO, pbuffer, strlen(pbuffer)); if (ret < 0) { perror("uthreads_test"); return EXIT_FAILURE; } uthread_mtx_lock(&mtx); uthread_cond_signal(&cond); uthread_mtx_unlock(&mtx); } uthread_exit(0); return 0; }
//-----------------------------------PART 3 int main(){ uthread_init(); struct binary_semaphore semaphore; binary_semaphore_init(&semaphore, 1); uthread_create(&foo, &semaphore); uthread_create(&foo, &semaphore); // uthread_join(2); uthread_exit(); exit(); }
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(); }
/* 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 (); }
static void tester3(long a0, void* a1){ int i = 0, ret; char pbuffer[SBUFSZ]; pprintf("tester3 starts\n"); while (i < 1) { i ++; /* uthread_mtx_lock(&mtx1); uthread_mtx_lock(&mtx3); */ pprintf("test3 about to broadcast\n"); uthread_cond_broadcast(&cond); sprintf(pbuffer, "thread 3: broadcast ends\n"); ret = write(STDOUT_FILENO, pbuffer, strlen(pbuffer)); if (ret < 0) { perror("uthreads_test"); /* XXX: we should really cleanup here */ exit(1); } /* uthread_mtx_unlock(&mtx1); uthread_mtx_unlock(&mtx3); */ } sprintf(pbuffer, "thread 3 exiting.\n"); ret = write(STDOUT_FILENO, pbuffer, strlen(pbuffer)); if (ret < 0) { perror("uthreads_test"); /* XXX: we should really cleanup here */ exit(1); } uthread_exit(a0); }
static void tester2(long a0, void* a1){ int i = 0, ret; char pbuffer[SBUFSZ]; //uthread_mtx_lock(&mtx); while (i < 1) { i ++; uthread_mtx_lock(&mtx1); pprintf("thread2 about to block\n"); //uthread_mtx_lock(&mtx3); uthread_cond_wait(&cond,&mtx1); sprintf(pbuffer, "thread 2 out of wait\n"); ret = write(STDOUT_FILENO, pbuffer, strlen(pbuffer)); if (ret < 0) { perror("uthreads_test"); /* XXX: we should really cleanup here */ exit(1); } uthread_mtx_unlock(&mtx1); //uthread_mtx_unlock(&mtx3); } sprintf(pbuffer, "thread 2 exiting.\n"); 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 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(); }
/* This function cannot be migrated to a different vcore by the userspace * scheduler. Will need to sort that shit out. */ void pthread_exit(void *ret) { struct pthread_tcb *pthread = pthread_self(); pthread->retval = ret; uthread_exit(); }
int child_thread( int* argv ) { uthread_exit( CHILD_EXIT_CODE ); fail( "It should not get here\n" ); }
int main(int argc,char** argv) { int i; if(argc!=2) { printf(1,"please write how much soldiers do you want (LESS THEN 64)\n"); goto out_err; } soldiersAmount=atoi(argv[1]); if(soldiersAmount>64 || soldiersAmount<2) { printf(1,"please write how much soldiers do you want (LESS THEN 64)\n"); goto out_err; } currentState[0][0]=AS; currentState[1][0]=AS; currentState[0][soldiersAmount+1]=AS; currentState[1][soldiersAmount+1]=AS; state=0; counter=0; binary_semaphore_init(&arrival,1); binary_semaphore_init(&departure,0); binary_semaphore_init(&printing,0); fatherPID=getpid(); signal(4,printArray); currentState[0][1]=P; for(i=2; i<=soldiersAmount;i++) { currentState[0][i]=Q; } uthread_init(); int tid; for(i=1;i<=soldiersAmount;i++) { tid = uthread_create(run, (void *) i); if (!tid) goto out_err; } while (currentState[0][i]!=F && currentState[1][i]!=F) { binary_semaphore_down(&printing); printArray(); } printArray(); printArray(); uthread_exit(); out_err: printf(1,"Faild to create thread, we go bye bye\n"); exit(); }
void wrapper(void) { threadTable.runningThread->entry(threadTable.runningThread->value); uthread_exit(); }