II must have problems. I. Priority Scheduling Using System; use system.threading;
Class test {static void main () {priorityTest priorityTest = new priorityTest (); threadstart startDelegate = new threadstart (priorityTest.ThreadMethod);
Thread threadOne = New thread (startdelegate); threadone.name = "threadone"; thread threadtwo = new thread (startdlegate); threadtwo.name = "threadtwo";
ThreadTwo.priority = ThreadPriority.belownormal; threadOne.start (); threadtwo.start ();
// allow counting for 10 seconds. Thread.sleep (10000); priorityTest.loopswitch = false;}}
Class prioritytest {bool loopswitch;
Public prioritytest () {loopswitch = true;
Public Bool Loopswitch {set {loopswitch = value;}}
Public void threadmethod () {long threadcount = 0;
while (loopSwitch) {threadCount ;} Console.WriteLine ( "{0} with {1,11} priority" "has a count = {2,13}", Thread.CurrentThread.Name, Thread.CurrentThread.Priority.ToString (), Threadcount.toString ("N0"));}} II. First Adjustive Algorithm & Best Adaptive Algorithm #include
} void sort () / * Best adaptation method sort * / {freeelist * m, * n, * q; m = head-> next; q = (freeelist *) malloc (freeelist); while (m- > Next! = null) {n = m-> next; while (n-> next! = null) {if ((! strcmp (m-> status, "f") && (! strcmp (n-> status , "F")) && (m-> length> n-> length)) {
Q-> Length = m-> length; q-> address = m-> address; m-> length = n-> length; m-> address = n-> address; n-> length = q-> length; N-> address = q-> address;} n = n-> next;
} M = m-> next;}} void output ()}} void output () {freeelist * OPT = head-> next; Printf ("% S% 8S% 8S / N", "address", "length", "status"); While (Opt! = NULL) {Printf ("% D% 10D% 10S / N", OPT-> Address, Opt-> length, OPT-> Status); OPT = OPT-> Next;} printf ("/ N ");
} Void Destory (freeelist * des) {freeelist * t = des-> next; if ((! strcmp (des-> status, "f") && (! strcmp (t-> next-> status, "f" ))) / * Upside down * / if (des-> address des-> length == t-> address && t-> address t-> length == t-> Next-> Address) {Des-> length = des-> length des-> next-> length des-> next-> next-> length; des-> next = t-> next-> next; free (t); free T-> Next);} if (! strcmp (des-> status, "f")) / * adjacent to the idle area * / if ((des-> address des-> length) == t-> Address) {des-> length = des-> length des-> next-> length; des-> next = t-> next; free (t);} if (! strcmp (t-> next-> status, "F")) / * under the neighboring * / {IF ((t-> address t-> length) == t-> Next-> address {des-> next-> status = "f "; Des-> next-> length = des-> next-> length des-> next-> next-> length; des-> next-> next = t-> next-> next; free (t-> Next);}} else des-> next-> status = "f";} FIT () / * The first adaptive method and the implementation of the best adaptive method * / {char * t = "f"; int i = 0 Freelist * cmp = head, * INS = (freeelist *) Malloc (Sizeof (free)), * DINS = head-> next; output (); ins-> length = 13; ins-> next = null; printf "INSERT J4 / N"); getch Ar (); while (slcmp (dins-> next-> status, "f")) DINS = DINS-> Next; if (DINS-> Next-> Length> INS-> Length ) {INS-> Address = DINS-> Next-> Address; DINS-> Next-> Address = INS-> Address INS-> Length; DINS-> Next-> length = DINS-> Next-> Length-INS -> Length; INS-> status = "
J4 "; INS-> Next = DINS-> Next; DINS-> next = I = 1;} else dins = dins-> next;} if (w == 1) sort (); output (); getchar (); While (cmp-> next-> status, "j1")) / * Find J1 and reclaim * / cmp = cmp-> next; t = cmp-> Next-> Status; Destory (CMP); IF (w == 1) sort (); OUTPUT (); Printf ("% s% s / n", t, "is free!"); cmp = head; while (strcmp (cmp-> next-> status , "J3")) / * Find J3 and recycle * / cmp = CMP-> next; t = cmp-> next-> status; destory (cmp); if (w == 1) sort (); OUTPUT () PRINTF ("% S% S / N", T, "IS free!");} Void main () {initlist (); printf ("firstfit! / N"); FIT (); getchar (); w = 1; initlist (); sort (); Printf ("Bestfit! / N"); FIT (); getchar ();