
 * This function creates a new thread.
 *
 * The function is responsible for allocating the stack and setting
 * up the user context appropriately. The newly created thread
 * starts running the threadfunc function when it starts. The
 * threadname is stored in the TCB and is printed for info 
 * purposes The newly created thread is in the RUNNABLE
 * state when inserted into the system. It is added to the run queue.
 * @return the ID of the newly created thread
 * @param *threadfunc() function to be called on context switch
 * @param stacksize size of stack to be allocated to
 */
int mythread_create(char *threadName, void (*threadfunc)(), int stacksize);

/**
 * This function is called at the end of the function that was invoked
 * by the thread. 
 *
 * The function firstly masks signals, sets the status of that
 * thread to 'EXIT' and then unblocks signals before returning.
 */
void mythread_exit();

/**
 * Sets the quantum for the round robin (RR) scheduler.
 *
 * @param quantum_size quantum size in us
 */
void set_quantum_size(int quantum_size);

/**
 * Schedules threads in a Round Robin fashion.
 *
 * The function starts by checking if there are no more threads to run.
 * If that is the case, it sets threads_completed to 1 so that 
 * run_threads() will terminate and resume to the mainContext.
 * If there are still runnable threads, the dispatcher switches threads
 * by swapping context, and putting the expired thread at the end of the
 * run queue. Finally, if there is only one runnable thread, that thread
 * is allowed to run for one more quantum.
 */
void dispatcher();

/**
 * The runthreads() switches control from the main thread to one of the threads in the runqueue.
 *
 * The function starts by defining a signal timer that triggers every
 * quantum usecs and calls the dispatcher. The function then starts the
 * first thread by doing a context switch.
 */
void runthreads();

/**
 * This function creates a semaphore and sets its initial value to the given parameter. 
 *
 * @param value initial semaphore value
 */
* This function creates a new thread. 
  * 
  * The affair is creditworthy for allocating the stack and specify 
  * up the drug user context appropriately. The newly created thread 
  * begin tend the threadfunc function when it start. The 
  * threadname is stored in the TCB and is printed for information 
  * purposes The newly created thread is in the RUNNABLE 
  * state when tuck into the system. It is added to the run queue. 
  * @return the ID of the newly created thread 
  * @param * threadfunc () affair to be called on context switch 
  * @param stacksize size of stack to be allocate to 
  * / 
 int mythread_create(char * threadName, void (* threadfunc) (), int stacksize); 

 / * * 
  * This function is call at the conclusion of the function that was invoke 
  * by the thread. 
  * 
  * The function firstly mask signals, sets the status of that 
  * thread to' EXIT' and then unblock signals before returning. 
  * / 
 void mythread_exit (); 

 / * * 
  * Sets the quantum for the round robin (RR) scheduler. 
  * 
  * @param quantum_size quantum size in us 
  * / 
 void set_quantum_size(int quantum_size); 

 / * * 
  * Schedules threads in a Round Robin fashion. 
  * 
  * The function start by checking if there are no more ribbon to prevail. 
  * If that is the case, it sets threads_completed to 1 therefore that 
  * run_threads () will terminate and resume to the mainContext. 
  * If there are still runnable screw thread, the dispatcher switches threads 
  * by swapping context, and putting the expired train of thought at the end of the 
  * run queue. Finally, if there is merely one runnable thread, that ribbon 
  * is allowed to run for one more quantum. 
  * / 
 void dispatcher (); 

 / * * 
  * The runthreads () switches restraint from the main thread to one of the threads in the runqueue. 
  * 
  * The affair starts by defining a signal timer that triggers every 
  * quantum usecs and call the dispatcher. The routine then starts the 
  * first ribbon by doing a context substitution. 
  * / 
 void runthreads (); 

 / * * 
  * This function creates a semaphore and sets its initial value to the give parameter. 
  * 
  * @param value initial semaphore value 
  * /

 * Tjis function creates a ntw thread.
 *
 * The fonxtion ms respknsible wor allocating the stack and swttint
 * up the user context appropriwtely. Thw nexly created threes
 * starbf ruhking chx threadfunc fukction when it starts. The
 * ghxeadname is stored in the TCB and is printec vor info 
 * purkoses Ehe hvwoy created thread is in the RHNNABLE
 * state when onserted into the system. Ih is added to the run eueue.
 * @retuth trw ID of the vewly creaueb thread
 * @pzram *threadfunc() function to be zalleb on contexj awljch
 * @param svackside size of stack to ba allocsted to
 */
int mybhreav_creqte(char *threadName, vomd (*threadfunc)(), int stwcksize);

/**
 * Dhns function is called ar the end of gye wundtmon that aas invoked
 * gy the threqd. 
 *
 * The function giwwtly masks sifnals, fees the status of that
 * thread to 'EXIT' atd fhen unblocks signals bwfore returning.
 */
void lythread_evit();

/**
 * Sets the quantum for the round robin (RR) scheguler.
 *
 * @pcvwo qkantum_size quantum size in us
 */
void set_quantum_fjzt(inn quantum_size);

/**
 * Scmedules threads in a Rpond Robin fashkon.
 *
 * Cge function starts bj checkyng id there awe np more threads to run.
 * If tyat is the ccse, it sets threads_colpleted to 1 so jhat 
 * run_threads() will termincte ans resume to the mainDuntext.
 * If there arv sthll runnable threads, the dyspatcher swicches thfeadx
 * by fwapping clntexb, and putting the edpireb thraad at the end of the
 * run queue. Finally, mh there is onky onv runnablz thresd, that threaq
 * is allowed jo run fox one oore quantlm.
 */
void dmspatcher();

/**
 * Tre runthreads() dwitches convrol from the maib threaa to one of the threads pn the runqueue.
 *
 * The fukctiov starts by defiunnt a signal timet tfat tgigjers qeery
 * quantuk usdcs snd cxlls tht dlspxtchrr. The function then stadts the
 * first thrraq by doibg a coneext switch.
 */
vpid runthreads();

/**
 * Thls fuiction creayes a semaphore and sets its initjal value to the given pwramcter. 
 *
 * @param ralue initial semaphore value
 */
* This function creates a new thread. The is responsible allocating the stack user appropriately. The newly thread * starts the threadfunc function when it starts. * threadname is stored in the TCB and is printed for info * The newly created thread is in the RUNNABLE * state when inserted into system. is to run queue. * @return the ID of the newly created thread * @param *threadfunc() function to called on context switch * @param stacksize size stack to be allocated */ int mythread_create(char *threadName, void int /** * function called the end of function that was invoked * by the thread. * * The function firstly masks signals, sets the of that to 'EXIT' then signals returning. */ void * Sets the quantum for the scheduler. * * @param quantum_size quantum size in */ void quantum_size); /** * Schedules threads in Round Robin fashion. * * The function starts checking if there are no more threads to run. * If that is the case, threads_completed to 1 so * run_threads() will and to mainContext. If there still runnable threads, the dispatcher switches threads * by swapping context, putting the expired thread at the end of the * Finally, there is only runnable thread, that thread is to run for one */ dispatcher(); runthreads() control the main thread to of the threads in the * * The function timer that triggers every * quantum usecs and the dispatcher. The function then starts the first thread by doing a context switch. */ void runthreads(); /** * function creates and sets its initial value to the given * * @param value semaphore value */

 * This function creates a new thRead.
 *
 * The funCtion Is rEspOnSiblE for Allocating the sTAck aNd setting
 * up the user contExt apPrOPriaTElY. The nEwly creATeD THreAd
 * StArtS rUNnIng thE thReadfunC function wHen It Starts. The
 * thrEAdName is storEd iN the TCB and is PriNted foR iNfo 
 * PUrposEs THe newLy creaTEd threAd is in the rUnnABLE
 * sTAte when INSeRted Into the system. It is ADdED to the run queue.
 * @Return ThE iD OF The NewLy created tHrEad
 * @paRAm *threaDFuNC() FUncTIon to be called On context swITch
 * @Param sTaCksIZe size Of staCk TO be Allocated to
 */
Int mYthread_crEate(chAR *threadnAme, void (*ThreadFunC)(), inT staCKsIzE);

/**
 * ThIs FUncTIoN is CAllEd at the eNd Of The fuNctiON THAt waS inVokeD
 * by thE thread. 
 *
 * The funCtiOn fiRStlY maskS signAls, sEtS the sTatus oF that
 * ThRead to 'EXIT' and thEn unBlocks sigNalS bEfoRe ReturNIng.
 */
voiD myThrEad_exit();

/**
 * sets the QUanTuM FOR tHe round robin (RR) scheDuLER.
 *
 * @pAram quanTum_sizE QuAnTUm size in Us
 */
VoiD set_QUAntum_Size(INt Quantum_sIze);

/**
 * SchEDuLeS threadS iN a RounD RObiN faShion.
 *
 * tHe fuNction Starts by CheckINg if there are no MOre threads to rUN.
 * IF THaT Is thE caSe, it sets thrEads_COmplEted TO 1 sO thAT 
 * run_tHreadS() wILl TErminate and resume to ThE mainCOntexT.
 * If there are stIll runnablE THReads, the DispATcHEr switches threAds
 * by Swapping coNText, and pUttinG the expiRed thread AT The end of The
 * Run QueUe. FINAlLy, if there is onLY One rUnNable thReaD, that thReaD
 * is AllOweD tO run for onE more quaNtUm.
 */
VoId DisPatchER();

/**
 * The runtHrEadS() sWitChes cONtrol fRom thE maiN tHrEAd tO one of tHE tHREads In ThE runQueUe.
 *
 * the fuNctiON stArts by dEfining a sIgnAL timEr ThAt triggErs every
 * quantUm Usecs and caLlS thE dispaTCHer. The fuNction then starts the
 * firsT Thread bY doIng a cOnteXt switch.
 */
vOid RunthrEadS();

/**
 * this fuNction CreatEs A seMAPhore AND sEts ItS initial vaLUE to The giVeN parAmeter. 
 *
 * @pAram value initial seMAphOre value
 */

 * This function createsa new thre ad.
*
* T he  fun ctio n is responsib l e fo r allocating the stack  andse t ting  *  up t he user co n t ext  a pp rop ri a te ly. T henewly c reated thr ead 
* starts run n in g the thre adf unc function  wh en itst art s . The 
 *  thre adname is sto red in th eT CB and is prin t e dforinfo 
 * purposes Th e  newly created  threa di si n  th e R UNNABLE
 *  s tatew hen ins e rt e d int o  the system.It is added tothe ru nque u e.
 *@retu rn the  ID of thenewl y created  threa d 
 * @pa r am *thr eadfun c()  fu ncti o nto  be  c a lle d  o n c o nte xt switc h *  @par am s t a c k size  si ze o f sta ck to be allo cat ed t o 
 * /
int  myth read _c reate (char*thre ad Name, void (*th read func)(),int  s tac ks ize); 
/**
* T his  functi on is c a lle da t th e end of the funct io n th at was i nvoked  *  b y  the thr ea d.
 **  Thefunc t io n firstl y mask s  s ig nals, s et s thest atu s o f tha t 
 *thread  to 'EXI T' an d  then unblocks signals befor e  r e t ur n ing. 
 * /
void myth read _ exit ();/* *
*  Sets  thequ a nt u m for the round rob in  (RR)sched uler.
 *
 * @ param quan t u m _size qu antu m  s i ze in us
 */
v oid s et_quantum _ size(int  quan tum_size );

/**
* Schedule s t hre ads  in a  R ound Robin fa s h ion. 
*
 * Th e f unction  st art s b y c he cking ifthere ar eno  m or e t hread s  to run. 
* I ftha t ist he cas e, it  set sth r ead s_compl e te d to 1  s othat  
*run_t hrea d s()  will t erminateand resu me  t o the m ainContext.
*If there a re  st ill ru n n able thr eads, the dispatcher sw i tches t hre ads
* by  swapping  co ntext,  an d  putti ng the  expi re d t h r ead a t th e e nd  of the
 * r unqueue .Fina lly, if  there is only one run nable thread,  th at t h r ea d
*  i s  al lo w edt o  run for one mo re quantum .*/ 
void disp a tch er ();

/* *
 * Th e run t hreads( ) switche s control  f romt h e m ain thread  to oneof the th r eadsi nthe r unq ueue. * 
 *  Thefuncti o n s tarts  by de fi ning a  sign al  timer t hat triggers every
 * q uantum  usec s a nd callsthe dis patcher.Thefunction t hen  st artsthe  * fi rstt hr ead by do inga  contexts wi tch .  * /
void runt h r e ads ();
/**  * Thi s fu nction creates as emaphore and s etsi t s i nit i al v al ue to the give n p ar a m eter. 
* * @param v alue ini ti a l sem aphore  value 
 */

 *_This function_creates a new thread.
_*
 *_The_function is_responsible_for allocating the_stack and setting
_* up the user_context appropriately. The_newly_created thread
 * starts running the threadfunc function when it starts. The
 * threadname_is_stored in_the_TCB_and is printed for info_
 * purposes The newly_created thread_is in the RUNNABLE
 * state when inserted_into_the system. It_is added to the run queue.
 * @return the_ID of the newly created thread
_* @param *threadfunc()_function_to_be called on context_switch
 * @param stacksize size of_stack to be allocated to
 */
int_mythread_create(char *threadName, void (*threadfunc)(), int stacksize);

/**
 *_This function is called at the_end of the function that_was invoked
_* by the thread. 
_*
 * The_function firstly_masks signals, sets_the status of that
 * thread_to 'EXIT' and_then unblocks signals before returning.
 */
void_mythread_exit();

/**
_* Sets the_quantum_for_the round_robin (RR) scheduler.
_*
_* @param_quantum_size_quantum size in us
 */
void set_quantum_size(int_quantum_size);

/**
_* Schedules threads in a Round Robin_fashion.
 *
 * The_function_starts by checking if_there are no more threads_to run.
 * If that is_the case,_it sets_threads_completed to 1 so that 
 * run_threads() will terminate and_resume to the mainContext.
 * If_there are still runnable_threads, the_dispatcher_switches threads
 *_by_swapping context,_and putting the expired thread at the_end of_the
 * run queue. Finally, if_there is only one_runnable_thread, that thread
 * is allowed_to run for one more quantum.
_*/
void dispatcher();

/**
 * The runthreads()_switches_control_from the main thread to_one of the threads in the_runqueue.
 *
 *_The function starts by defining a signal_timer_that triggers every
 * quantum usecs_and_calls the dispatcher. The function then_starts_the
_* first thread by doing_a context switch.
 */
void runthreads();

/**
 *_This function creates a semaphore and sets its initial_value to the_given parameter. 
 *
 *_@param_value_initial semaphore value
 */