Skip to content

Commit

Permalink
Merge branch 'pthread_createyeild' of https://github.com/Sail338/Oper…
Browse files Browse the repository at this point in the history
…atingSystems into pthread_createyeild
  • Loading branch information
sara committed Feb 7, 2018
2 parents 0884b3c + 43c3305 commit 7fde071
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
6 changes: 3 additions & 3 deletions Asst1/Makefile
Expand Up @@ -8,11 +8,11 @@ Target: my_pthread.a
util: util.h
$(CC) $(CFLAGS) util.c
my_pthread.a: my_pthread.o
$(AR) libmy_pthread.a my_pthread.o util.o
$(AR) libmy_pthread.a util.o my_pthread.o
$(RANLIB) libmy_pthread.a

my_pthread.o: my_pthread_t.h util.o
$(CC) -pthread $(CFLAGS) my_pthread.c util.o
my_pthread.o: my_pthread_t.h util
$(CC) -pthread $(CFLAGS) my_pthread.c

clean:
rm -rf testfile *.o *.a
2 changes: 1 addition & 1 deletion Asst1/client.c
Expand Up @@ -4,7 +4,7 @@ int func(){
printf("new thread created\n");
printf("HELLO WORLD\n");
printf("KEK\n");
setcontext(scheduler->current->thread);
setcontext(&(scheduler->current->thread));
return 0;

}
Expand Down
24 changes: 9 additions & 15 deletions Asst1/my_pthread.c
Expand Up @@ -18,8 +18,8 @@ void sig_hanlder(){


}
threadNode * createNewNode(threadNode *node,int level,ucontext_t newthread,int numSlices,double spawnTime,my_pthread_t *thread,void*(*function)(void*),void * arg){

threadNode * createNewNode(threadNode *node,int level,int numSlices,double spawnTime,my_pthread_t *thread,void*(*function)(void*),void * arg){
ucontext_t newthread;
node = (threadNode *)malloc(sizeof(threadNode));
node -> tid = &node;

Expand All @@ -40,16 +40,12 @@ threadNode * createNewNode(threadNode *node,int level,ucontext_t newthread,int
newthread. uc_stack.ss_sp=malloc(MEM);
newthread. uc_stack.ss_size=MEM;
newthread. uc_stack.ss_flags=0;
node ->thread = malloc(sizeof(ucontext_t));
makecontext(&newthread, (void*)(function), 1,arg);
}

node ->thread = malloc(sizeof(ucontext_t*));
//node ->thread = malloc(sizeof(ucontext_t*));

node->thread = &newthread;
if (function == NULL){

}
node->thread = newthread;
return node;

}
Expand Down Expand Up @@ -78,17 +74,15 @@ int my_pthread_create(my_pthread_t * thread, pthread_attr_t * attr, void *(*func
scheduler -> timer.it_value.tv_usec = 25000;
scheduler ->timer.it_interval.tv_sec = 0;
scheduler ->timer.it_interval.tv_usec = 25000;
scheduler->current = createNewNode(scheduler->current,0,curr,25,(double)time(NULL),NULL,NULL,NULL);

scheduler->current = NULL;
scheduler->current = createNewNode(scheduler->current,0,25,(double)time(NULL),NULL,NULL,NULL);


}
//create a threadNode
ucontext_t newthread;
threadNode * node = NULL;
node = createNewNode(node,0,newthread,25,(double)time(NULL),thread,function,arg);
getcontext(&curr);
scheduler->current->thread = &curr;
swapcontext(scheduler->current->thread,node->thread);
node = createNewNode(node,0,25,(double)time(NULL),thread,function,arg);
swapcontext(&(scheduler->current->thread),&(node->thread));
printf("HEY I DID I THING\n");
/**
*
Expand Down
2 changes: 1 addition & 1 deletion Asst1/util.h
Expand Up @@ -19,7 +19,7 @@
typedef struct threadNode
{
struct threadNode * next;
ucontext_t* thread;
ucontext_t thread;
double spawnTime;
uint tid;
int qlevel;
Expand Down

0 comments on commit 7fde071

Please sign in to comment.