Beispiel #1
0
int
main() {
    char c1 = 'a';
    char c2 = 'b';
    char c3 = 'c';
    char c4 = 'd';
    int j;
    int tid1;
    int tid2;
    int tid3;
    int tid4;

    tid1 = UserThreadCreate(SimpleThread, (void*) &c1);
    tid2 = UserThreadCreate(SimpleThread, (void*) &c2);
    tid3 = UserThreadCreate(SimpleThread, (void*) &c3);
    tid4 = UserThreadCreate(SimpleThread, (void*) &c4);

    for (j = 0; j < 10; j++) {
        PutChar('m');
        PutInt(j);
        PutChar('\n');
    }

    UserThreadJoin(tid1);
    UserThreadJoin(tid2);
    UserThreadJoin(tid3);
    UserThreadJoin(tid4);

    /* not reached */
    return 0;
}
Beispiel #2
0
int
main() {
	sem_t sem;
	struct s a, b, c, d;
    int tid1;
    int tid2;
    int tid3;
    int tid4;
	sem = sem_create("usersem test", 1);
	a.sem = &sem; a.c = 'a';
	b.sem = &sem; b.c = 'b';
	c.sem = &sem; c.c = 'c';
	d.sem = &sem; d.c = 'd';
    tid1 = UserThreadCreate(SimpleThread, (void*) &a);
    tid2 = UserThreadCreate(SimpleThread, (void*) &b);
    tid3 = UserThreadCreate(SimpleThread, (void*) &c);
    tid4 = UserThreadCreate(SimpleThread, (void*) &d);

    UserThreadJoin(tid1);
    UserThreadJoin(tid2);
    UserThreadJoin(tid3);
    UserThreadJoin(tid4);
	sem_destroy(sem);

	return 0;
}
Beispiel #3
0
int main() {
    int thread_id;
    PutString("Je lance le Thread 1\n");
    thread_id = UserThreadCreate(print, (void *)1);
    if (thread_id > 0) {
        UserThreadJoin(thread_id);
    } else {
        PutString("Erreur UserThreadCreate\n");
    }
    PutString("Fin Thread 1\n");
    PutString("Je lance le Thread 2\n");
    thread_id = UserThreadCreate(print, (void *)2);
    if (thread_id > 0) {
        UserThreadJoin(thread_id);
    } else {
        PutString("Erreur UserThreadCreate\n");
    }
    PutString("Fin Thread 2\n");
    PutString("Je lance le Thread 3\n");
    thread_id = UserThreadCreate(print, (void *)3);
    if (thread_id > 0) {
        UserThreadJoin(thread_id);
    } else {
        PutString("Erreur UserThreadCreate\n");
    }
    PutString("Fin du main : \n");
    return 0;
}
int main()
{
    int id[NB_THREADS];

    int i;
    for(i=0;i<NB_THREADS;i++)
    {
        id[i] = UserThreadCreate(&fun, 0);
        //Some check for the threads creation
        if(id[i] < 0)
        {
            PutString("Error while creating thread\n");
            // Wait for putstring
            UserThreadJoin(id[i]-1, 0);
            return -1;
        }
    }

    for(i=0;i<NB_THREADS;i++)
    {
        //Joining all threads
        if(UserThreadJoin(id[i], 0) == -1)
        {
            PutString(" joined failed! ");
        }
    }

    PutString("\nParent finish\n");
    return 0;
}
Beispiel #5
0
int main(int argc, char** argv) {
	int i = 7;

	int tid = UserThreadCreate(Thread, &i);
	UserThreadJoin(tid);
	i = 7;
	tid = UserThreadCreate(Thread, &i);
	UserThreadJoin(tid);

	return 0;
}
Beispiel #6
0
int main(){
	int t1, t2;
	t1 = UserThreadCreate(print,(void *) 'a');
	t2 = UserThreadCreate(print,(void *) 'e');

	UserThreadJoin(t1);
	UserThreadJoin(t2);
	PutChar('\n');


	return 0;
}
Beispiel #7
0
int main(){

	int t1, t2;
	t1 = UserThreadCreate(print,(void *) 7);
	t2 = UserThreadCreate(print,(void *) 8);


	UserThreadJoin(t1);
	UserThreadJoin(t2);
	SynchPutString("Je suis le thread principal");
	//char a = SynchGetChar();
	


	return 0;
}
int main()
{
    int id[THREAD_NUMBER];
    int i;

    // Call init explicitly to avoid semaphore creation problem in cast of
    // concurrency
    memory_init();

    for (i = 0; i < THREAD_NUMBER; i++)
    {
        id[i] = UserThreadCreate(&fn, NULL);
        if (id[i] < 0)
        {
            PutString("Thread creation failed !\n");
            return -1;
        }
    }
    for (i = 0; i < THREAD_NUMBER; i++)
    {
        if (UserThreadJoin(id[i], NULL) != 0)
        {
            PutString("Error while joining\n");
            return -1;
        }
    }

    if (!not_all_freed())
        PutString("ok");

    return 0;
}
Beispiel #9
0
int main(int argc, char** argv) {
	char a = 'a', b = 'b', c = 'c';
	int tidA, tidB, tidC;

	tidA = UserThreadCreate(Thread, &a);
	tidB = UserThreadCreate(Thread, &b);
	tidC = UserThreadCreate(Thread, &c);

	

	UserThreadJoin(tidA);
	UserThreadJoin(tidB);
	UserThreadJoin(tidC);


	return 0;
}
int main()
{
	PutString("\n-----------------------------------------\n");
	PutString("Lancement du test testJoinThreadFini2 : \n");
	PutString("Lance 2 threads et les attend, le 2e attendu est deja termine.\n");
	PutString("-----------------------------------------\n");
	int tidf, tidg;
	int th_ret;
	tidg = UserThreadCreate(g, 0);
	tidf = UserThreadCreate(f, 0);
	if(UserThreadJoin(tidf, &th_ret) == -1)
		PutString("Erreur join sur f\n");
	if(UserThreadJoin(tidg, &th_ret) == -1)
		PutString("Erreur join sur g\n");
	PutString("Fin du main\n");
    return 0;
}
Beispiel #11
0
void f(void* arg)
{
	int* tidg = (int*)arg;
	PutString("Thread f\n");
	if(UserThreadJoin(*tidg, 0) == -1)
		PutString("Erreur join de f sur g\n");
	PutString("f fini\n");
}
Beispiel #12
0
int main() {
    int i = 0;
    int t1;
    for (i=0; i<3000; i++) {
       t1 = UserThreadCreate(print2, (void *)'c');
       UserThreadJoin(t1);
   }
    return 0;
}
Beispiel #13
0
void Thread2(void* arg) {
	int tid = *(int*) arg;
	int i;
	for (i = 0; i < 500; i++) {
		PutChar('d');
	}
	PutChar('Q');
	UserThreadJoin(tid);
	PutChar('Z');
	UserThreadExit();
}
Beispiel #14
0
int main() {
    int m,n;
    int t1;
    t1 = UserThreadCreate(print, (void *)'z');
    UserThreadJoin(t1);
    for (m=0; m<3; m++) {
        for (n=0; n<3000; n++) {}
        PutChar('K');
    }
    return 0;
}
Beispiel #15
0
int
main()
{
	char number = '2';
        int i,j;
	j=UserThreadCreate(f, (void *) &number);
        UserThreadJoin(j);
	for(i=0; i<2000; i++){};
		PutString("Inside Main Thread \n");
	UserThreadExit();			
	return 0;
}
void *fun(void* arg)
{
    int tid = (int)arg;
    int i = 0;

    for (i = 0; i < 1000; i++);

    PutString("T2 joining...\n");
    if (UserThreadJoin(tid, 0) == -2)
        PutString("ok\n");
    return 0;
}
Beispiel #17
0
void Thread(void* arg) {
	int* i = (int*) arg;
	PutChar('T');
	PutInt(*i);
	PutChar('\n');
	(*i)--;
	if (*i > 0) {
		int tid = UserThreadCreate(Thread, arg);
		UserThreadJoin(tid);
	}
	UserThreadExit();
}
int main()
{
    //PutString("Parent start\n");
    int id[NB_THREADS-1];

    int i;
    for(i=0;i<NB_THREADS-1;i++)
    {
        id[i] = UserThreadCreate(&fun, 0);

        //Some check for the threads creation
        if(id[i] == -1)
        {
            PutString("Error while creating thread\n");
            return -1;
        }
    }

    //killed 1 thread    
    UserThreadJoin(UserThreadCreate(last_killed_thread, 0),0);
    //create new other thread
    UserThreadCreate(last_killed_thread, 0);

    for(i=0;i<NB_THREADS-1;i++)
    {
        //Joining all threads
        if(UserThreadJoin(id[i], 0) == -1)
        {
            PutString(" joined failed! ");
        }
        else
        {
            PutString(" joined successfull! ");
        }
    }

    PutString("Parent finish\n");
    return 0;
}
void g(void* arg)
{
	int i;
	int* tidh = (int*)arg;
	if(PutString("thread g\n") == -1)
		PutString("Erreur putstring\n");
	for (i = 0 ; i < 50000 ; i++)
	{
	}
	if(UserThreadJoin(*tidh, 0) == -1)
		PutString("Erreur join de g sur h\n");
	PutString("Thread g fini\n");
}
Beispiel #20
0
int main(int argc, char** argv) {
	char a = 'a', b = 'b', c = 'c';
	int tidA, tidB, tidC;
	int tids[4];
	int i;

	tidA = UserThreadCreate(Thread, &a);
	tidB = UserThreadCreate(Thread, &b);
	tidC = UserThreadCreate(Thread, &c);
	
	for (i = 0; i < 4; i++) {
		tids[i] = UserThreadCreate(Thread2, &tidA);
	}

	UserThreadJoin(tidB);
	UserThreadJoin(tidC);
	
	for (i = 0; i < 4; i++) {
		UserThreadJoin(tids[i]);
	}

	return 0;
}
int main()
{
  char i;
  char id[NB_THREADS];
  for(i=0;i<NB_THREADS; i++)
  {
    id[(int)i] = UserThreadCreate(&fun,NULL);
  }
  for(i=0;i<NB_THREADS; i++)
  {
    id[(int)i] = UserThreadJoin(id[(int)i],NULL);
  }
  PutString("Child ending\n");
  return 0;
}
Beispiel #22
0
int main()
{
	PutString("\n-----------------------------------------\n");
	PutString("Lancement du test threadMulJoin : \n");
	PutString("Test le Join multiple sur le meme thread.\n");
	PutString("Doit afficher \"Erreur join ...\".\n");
	PutString("-----------------------------------------\n");
	int tidf, tidg;
	tidg = UserThreadCreate(g, 0);
	tidf = UserThreadCreate(f, &tidg);
	if(UserThreadJoin(tidg, 0) == -1)
		PutString("Erreur join du main sur g\n");
	PutString("Fin du main\n");
    return 0;
}
int main()
{
    int *retCode;
    int tid = 0;

	PutString("Parent start\n");
	tid = UserThreadCreate(&fun, 0);
    UserThreadJoin(tid, (void **)(&retCode));

    PutString("Exit code of child is ");
    PutInt((int)retCode);

	PutString("\nParent finish\n");
	return 0;
}
int main()
{
	PutString("\n-----------------------------------------\n");
	PutString("Lancement du test testJoinAttenteRec : \n");
	PutString("Lance 3 threads f, g et h. Le main attend f qui attend g qui attend h.\n");
	PutString("-----------------------------------------\n");
	int tidf, tidg, tidh;
	tidh = UserThreadCreate(h, 0);
	tidg = UserThreadCreate(g, &tidh);
	tidf = UserThreadCreate(f, &tidg);

	if(UserThreadJoin(tidf, 0) == -1)
		PutString("Erreur join du main sur f\n");
	PutString("Fin du main\n");
    return 0;
}
int main()
{
	int tid1 = UserThreadCreate(&fun2, 0);
    int tid2 = UserThreadCreate(&fun, (void *)tid1);
    if (tid1 == -1 || tid2 == 1)
    {
        PutString("Error while creating thread\n");
        return -1;
    }

	PutString("T1 joining...\n");
    if (UserThreadJoin(tid1, 0) != 0)
        PutString("Error !\n");

	return 0;
}
int main()
{
	int sem = UserSemaphoreCreate("sem",1);
	int tid[10];
	int i;
	for(i=0;i<NB_THREADS;i++)
	{
		tid[i] = UserThreadCreate(&fun, &sem);
	}

	for(i=0;i<NB_THREADS;i++)
	{
		UserThreadJoin(tid[i],0);
	}

	return 0;
}
int main()
{
    file = Open("test");
    char id[NB_THREADS];

    int i;
    for(i=0;i<NB_THREADS; i++)
    {
        id[i] = UserThreadCreate(fun,(void*) i);
    }

    for(i=0;i<NB_THREADS; i++)
    {
        UserThreadJoin(id[i],NULL);
    }
    PutString("END\n");
    Close(file);
    return 0;
}
int main()
{
	PutString("\n-----------------------------------------\n");
	PutString("Lancement du test threadMulJoin : \n");
	PutString("Cree un thread et recupere sa valeur de retour avec Join puis l'affiche.\n");
	PutString("-----------------------------------------\n");
	int tidf;
	int ret;
	tidf = UserThreadCreate(f, 0);
	if(UserThreadJoin(tidf, &ret) == -1)
		PutString("Erreur join du main sur f\n");
	else
	{
		PutString("Code retour f :  ");
		PutInt(ret);
		PutString("\n");
	}
	PutString("Fin du main\n");
    return 0;
}
Beispiel #29
0
int main() {
    int t2;
    t2 = UserThreadCreate(print, (void *)'x');
    UserThreadJoin(t2);
    return 0;
}