C # writer writer writing (fair competition reader)

xiaoxiao2021-03-06  71

Rand = random;} public void read () {for (int i = 0; i <5; i ) {int P = rand.next (0, book.numofpages); int a = book [p]; thread.sleep (Rand.Next (0,100));}}} public class Writer {Private book book; private land} {book = b; rand = random;} public void write () {for (INT i = 0; i <5; i ) {int P = rand.next (0, book.numofpages); book [p] = rand.next (50, 100); thread.sleep (Rand.Next (0,100)) }}} Public class test {public static void main (string [] args) {book book = new book (5); random random = new random (); string [] readernames = {"Pig Eight Rings", "Tang Yan", "Sand monk"}; string [] Writernames = {"Guanyin Bodhisattva", "Sun Wukong", "Jade Emperor"}; thread [] readertHreads = New Thread [3]; thread [] Writerthreads = new thread [3]; for INT i = 0; i <3; i ) {reader reader = new reader (book, random); readERTHREADS [i] = new threeread (Reader.Read); readERTHREADS [i] .Name = readernames [i ]; Writer Writer = New Writer (Book, Random); Writerthreads [i] = new thread (N Ew threadstart (Writer.write)); Writerthreads [i] .Name = Writernames [i];} for (int i = 0; i <3; i ) {readertHreads [i] .start (); Writerthreads [i]. START ();}}}

转载请注明原文地址:https://www.9cbs.com/read-109627.html

New Post(0)