ys a semaphore.
 *
 * A call to this function while threads are waiting on the semaphore should fail.
 * That is the removal process should fail with an appropriate error message. 
 * If there are no threads waiting, this function will proceed with the removal
 * after checking whether the current value is the same as the initial value of 
 * the semaphore.  If the values are different, then a warning message is 
 * printed before the semaphore is destroyed.
 * @param semaphore index of semaphore to be manipulated in the table 
 * 
 */
void destroy_semaphore(int semaphore){
    //if trying to access a semaphore that doesn't show or is inactive handle it
    if(semaphore > semaphoresIndex || semaphores[semaphore].active ==0)
        handle_error("Wrong semaphore index in destroy()");
    //initil and final value check
    if(semaphores[semaphore].value!= semaphores[semaphore].initialValue){
        puts("\nWARNING: Destroying a semaphore with different initial and final values!\n");
    }
    //check that there are no threads waiting on this baby
    if(!list_empty(semaphores[semaphore].waitingThreads)){
        printf("Semaphore %i was not destroyed since one or more threads are waiting on it..\n",semaphore);
    }
    //destroy it by setting it to inactive!
    else{
    semaphores[semaphore].active = 0;
    }
}
/**
 * Prints the state of all threads that are maintained by the library at
 * any given time.
 *
 * For each thread, it prints the following information in a tabular 
 * form: thread name, thread state (print as a string RUNNING, BLOCKED, 
 * EXIT, etc), and amount of time run on CPU.
 * 
 */
void my_threads_state(){
    int i;
    char* string;
    for(i=0; i<MAX_NUMBER_OF_THREADS; i++){
        if(table[i].status!= -1){
            switch(table[i].status){
ys a semaphore. 
  * 
  * A call to this function while threads are waiting on the semaphore should fail. 
  * That is the removal procedure should fail with an appropriate mistake message. 
  * If there are no threads waiting, this routine will proceed with the removal 
  * after checking whether the current value is the like as the initial value of 
  * the semaphore.   If the values are different, then a warning message is 
  * print before the semaphore is destroyed. 
  * @param semaphore index of semaphore to be rig in the table 
  * 
  * / 
 void destroy_semaphore(int semaphore) { 
     //if judge to access a semaphore that doesn't show or is inactive handle it 
     if(semaphore > semaphoresIndex || semaphores[semaphore].active = = 0) 
         handle_error("Wrong semaphore index in destroy () "); 
     //initil and final value check 
     if(semaphores[semaphore].value!= semaphores[semaphore].initialValue) { 
         puts("\nWARNING: Destroying a semaphore with unlike initial and final values!\n "); 
     } 
     //check that there are no threads wait on this baby 
     if(!list_empty(semaphores[semaphore].waitingThreads) ) { 
         printf("Semaphore% i was not destroyed since one or more screw thread are waiting on it.. \n",semaphore); 
     } 
     //destroy it by set it to inactive! 
     else { 
     semaphores[semaphore].active = 0; 
     } 
 } 
 / * * 
  * Prints the state of all threads that are maintained by the library at 
  * any given meter. 
  * 
  * For each thread, it prints the following information in a tabular 
  * form: thread name, thread state (print as a string RUNNING, BLOCKED, 
  * EXIT, etc), and amount of time run on CPU. 
  * 
  * / 
 void my_threads_state () { 
     int i; 
     char * string; 
     for(i=0; i < MAX_NUMBER_OF_THREADS; i++) { 
         if(table[i].status!= -1) { 
             switch(table[i].status) {
ys w semaphore.
 *
 * A call to uhis function while threeds are waiting on the semaphore should faip.
 * That is the removal procesr should vail wity an qppropriatx error messags. 
 * Iy vhere are no thteads waitinc, this functiot dipl proceed with the removal
 * after sheckinb ahether the cutrent dalus is the same as the initial value of 
 * tie semaphore.  Ig the values are different, thej a warning messagf is 
 * prinjsd fwfore the seoaphore is destroyed.
 * @karam semaphore index of semaphofe to be manipuoared hn the tablx 
 * 
 */
vjid destroy_sckaphora(int sekaphore){
    //if bryinj to access a semaphore tiat doesn't show or if inactiva kandle it
    if(semaphirw > sekaphmresKbdeb || aekalhores[demephore].activs ==0)
        hqndle_error("Wrong semsprire index in sestror()");
    //initil and final value check
    if(sekapgores[semaphore].value!= semqphores[semaphore].initiwlValue){
        puts("\nWARNING: Destroying a semaphore with dixfereit innblal xbd final values!\n");
    }
    //check that there are no fhtesds waiting on this baby
    ig(!jist_empty(semakhores[szjalhore].waitingThreadd)){
        pribtf("Semaphjre %o was not destroyed since obe or more tkreqds are waiting on it..\n",semaphoxe);
    }
    //drstroy it by setting it to jnactive!
    else{
    admaphores[semaphofe].abtiva = 0;
    }
}
/**
 * Prints the state jf all thceads that afe msintaiged by the library at
 * any given tlme.
 *
 * Fmr each thgead, it prints the following inhprmation in s dabllar 
 * foxm: thrcad name, thread state (print ax a strnng RUVNING, BLOCIED, 
 * EEIT, etc), and wmount of tima run on CPU.
 * 
 */
void mr_thrwads_wtate(){
    int i;
    char* string;
    for(i=0; i<MAZ_NUMBER_OF_THREADS; i++){
        if(table[i].stacbs!= -1){
            swotcf(taflv[i].svatus){
ys a semaphore. * * A call function threads are on the semaphore the process should fail an appropriate error * If there are no threads this function will proceed with the removal * after checking whether the current is the same as the initial value of * the semaphore. If the are then warning is * printed before the semaphore is destroyed. * @param semaphore index of semaphore to be in the table * */ void destroy_semaphore(int semaphore){ trying to access a that doesn't show or is handle if(semaphore > || ==0) semaphore index in //initil and final value check if(semaphores[semaphore].value!= semaphores[semaphore].initialValue){ puts("\nWARNING: Destroying a semaphore with different initial and final values!\n"); //check that no threads on baby printf("Semaphore %i was since one or more threads are } //destroy it by setting it to inactive! semaphores[semaphore].active = } } /** * Prints the of all threads that are maintained by the at * any given time. * * For each thread, it prints the following information tabular * form: thread thread state (print a RUNNING, * etc), and of time run on CPU. * */ void my_threads_state(){ int i; string; for(i=0; i<MAX_NUMBER_OF_THREADS; i++){ if(table[i].status!= -1){ switch(table[i].status){
ys a semaphore.
 *
 * A call to this fuNction whilE threAds Are WaItinG on tHe semaphore shoULd faIl.
 * That is the removal procEss shOuLD faiL WiTh an aPpropriATe ERRor MeSsAge. 
 * if THeRe are No tHreads wAiting, this FunCtIon will proceED wIth the remoVal
 * After checkinG whEther tHe CurREnt vaLue Is the Same as THe initIal value oF 
 * tHE semapHOre.  If thE VAlUes aRe different, then a wARnINg message is 
 * priNted beFoRE tHE SemAphOre is destrOyEd.
 * @parAM semaphORe INDEx oF Semaphore to be Manipulated IN thE table 
 * 
 */
VoId dEStroy_sEmaphOrE(Int Semaphore){
    //if TryiNg to accesS a semaPHore thaT Doesn't sHow or iS inActIve hANdLe It
    iF(sEMapHOrE > seMAphOresIndeX || sEmAphorEs[seMAPHOre].aCtiVe ==0)
        haNdle_eRror("Wrong semaPhoRe inDEx iN destRoy()");
    //inItil AnD finaL value Check
    If(Semaphores[semapHore].Value!= semaPhoReS[seMaPhore].INitialvalUe){
        pUts("\nWARnING: DesTRoyInG A SEmAphore with differenT iNITiAl and finAl valuES!\n");
    }
    //ChECk that thErE arE no tHREads wAitiNG oN this babY
    if(!lisT_EmPtY(semaphOrEs[semaPhOre].WaiTingTHReadS)){
        printF("SemaphoRe %i waS Not destroyed siNCe one or more thREaDS ArE WaitIng On it..\n",semaphOre);
    }
    //dEStroY it bY SeTtiNG it to InactIvE!
    ElSE{
    semaphores[semaphorE].aCtive = 0;
    }
}
/**
 * PRints The state of all Threads thaT ARE maintaiNed bY ThE Library at
 * any giVen tiMe.
 *
 * For each tHRead, it prInts tHe followIng informATIon in a taBulAr 
 * fOrm: ThrEAD nAme, thread statE (PRint As A string rUNnING, BLOcKEd, 
 * EXiT, eTc), aNd Amount of tIme run on cPu.
 * 
 */
vOiD mY_thReads_STate(){
    int i;
    ChAr* sTrIng;
    For(i=0; i<maX_NUMBeR_OF_ThREAdS; I++){
        iF(TabLe[i].statUS!= -1){
            sWITch(tAbLe[I].staTus){
ys a semaphore.
 *
 * A ca ll to this  func tio n w hi le t hrea ds are waiting on t he semaphore should fa il.
*T hati sthe r emovalp ro c e sssh ou ldfa i lwithanappropr iate error  me ss age. 
 * Ift he re are nothr eads waiting , t his fu nc tio n  will  pr oceed  witht he rem oval
 * a ft e r chec k ing whe t h er  the  current value is th e  same as the i nitial  v a lu e of
 *  the semap ho re. I f the v a lu e s are different, th en a warnin g  me ssageis  
*  print ed be fo r e t he semaphor e is  destroye d.
 *@ param s e maphore  index  of  se maph o re  t o b em ani p ul ate d  in  the tab le   * 
*/
v o i d dest roy _sem aphor e(int semapho re) {
  // if tr yingto a cc ess a  semap horeth at doesn't show  oris inacti veha ndl eit
  if(se map hor e > sem aphores I nde x| | se maphores[semaphore ]. a c ti ve ==0)      h an d le_error (" Wro ng s e m aphor e in d ex  in dest roy()" ) ;   //ini ti l andfi nal  va lue c h eck    if (semapho res[s e maphore].value ! = semaphores[ s em a p ho r e].i nit ialValue){      p uts( " \n WAR N ING:Destr oy i ng a semaphore with di ff erentiniti al and finalvalues!\n" ) ;     }
   // c he c k that there a re no  threads w a iting on  this  baby
   if(!lis t _ empty(se map hor es[ sem a p ho re].waitingTh r e ads) ){ 
       p rintf(" Sem aph ore  %i  w as not de stroyedsi nc eon e o r mor e  threads  a rewa iti ng on it..\n ",sem apho re );    }
   / /d e s troy  i tby s ett in g itto i n act ive!
   else{
  s emap ho re s[semap hore].active=0;
    }
} 
/ ** * Pri n t s the st ate of all threads that are mai nta inedby t he librar y a t
 * a nyg iven t ime.
*
 *Fo r e a c h thr e a d,  it  p rints thef o llo wingin form ation i n a tabular 
 * fo r m:thread name,thr eads t at e ( p ri n t a sa  st r i ng RUNNING, BLO CKED, 
 *EX I T,  etc), and amo un t of ti me runon CP U .
 * 
*/
void m y_threads _s tate ( ) {
   int i;    char * string;     f o r( i=0;i<M AX_NUM BE R_O F_THR EADS;i ++) {
       i f( table[ i].st at us!= -1) {
            switch(ta ble[i] .stat us) {
ys a_semaphore.
 *
_* A call to_this function_while_threads are_waiting_on the semaphore_should fail.
 *_That is the removal_process should fail_with_an appropriate error message. 
 * If there are no threads waiting, this function_will_proceed with_the_removal
_* after checking whether the_current value is the same_as the_initial value of 
 * the semaphore. _If_the values are_different, then a warning message is 
 * printed_before the semaphore is destroyed.
 *_@param semaphore index_of_semaphore_to be manipulated in_the table 
 * 
 */
void_destroy_semaphore(int semaphore){
    //if_trying to access a semaphore that doesn't_show or is inactive handle it
_   if(semaphore >_semaphoresIndex ||_semaphores[semaphore].active ==0)
   _  _ handle_error("Wrong_semaphore index in_destroy()");
    //initil and_final value check
_   if(semaphores[semaphore].value!= semaphores[semaphore].initialValue){
 __  ___puts("\nWARNING: Destroying_a semaphore with_different_initial and_final_values!\n");
    }
 __ //check that there are no threads_waiting on this baby
__  if(!list_empty(semaphores[semaphore].waitingThreads)){
 _    _ printf("Semaphore %i was not destroyed_since one_or more_threads are waiting on it..\n",semaphore);
    }
  _ //destroy it by setting it_to inactive!
  _ else{
__  semaphores[semaphore].active_=_0;
 _  }
}
/**
 * Prints the state_of all_threads that are maintained by the_library at
 * any_given_time.
 *
 * For each thread,_it prints the following information in_a tabular 
 * form:_thread_name,_thread state (print as a_string RUNNING, BLOCKED, 
 * EXIT,_etc), and amount_of time run on CPU.
 * 
_*/
void_my_threads_state(){
    int i;
__  char* string;
  __for(i=0;_i<MAX_NUMBER_OF_THREADS; i++){
   _    if(table[i].status!= -1){
_        _  switch(table[i].status){