c# - How to add another one consumer? -
how add 1 consumer in program? trying this, not working... find post how add consumers in multithreading , not need, becouse dont need lock... , need without class or that. code.. please :)
private int occupiedbuffercount = 0; private int occupiedbuffercount2 = 0; int = 0; private void producer() { int how_much_numbers = convert.toint32(textbox3.text); using (streamwriter writer = new streamwriter("random_skaiciai.txt")) { (i = 0; < how_much_numbers; i++) { monitor.enter(this); if ((occupiedbuffercount == 1) || (occupiedbuffercount2 == 1)) { monitor.wait(this); } ++occupiedbuffercount; buffer = i; random rnd = new random(); numbers = i; //numbers = rnd.next(nuo, iki); writer.writeline(numbers + ""); prm = false; fib = false; monitor.pulse(this); monitor.exit(this); if (iscanceled == true) break; } writer.close(); set_p(kiek); } } private void consumer1() { int how_much_numbers = convert.toint32(textbox3.text); using (streamwriter writer = new streamwriter("primary_numbers.txt")) { while (i < how_much_numbers) { monitor.enter(this); if ((occupiedbuffercount == 0)) { monitor.wait(this); } --occupiedbuffercount; if (numbers != 0) if (prime_num(numbers) == true) { writer.writeline(numbers + ""); } prm = true; monitor.pulse(this); monitor.exit(this); if (iscanceled == true) break; } writer.close(); } } private void consumer2() { int how_much_numbers = convert.toint32(textbox3.text); using (streamwriter writer = new streamwriter("fibon_numbers.txt")) { while (i < how_much_numbers) { monitor.enter(this); if ((occupiedbuffercount2 == 0)) { monitor.wait(this); } --occupiedbuffercount2; if (numbers != 0) if (isfibonaci(numbers) == true) writer.writeline(numbers + ""); monitor.pulse(this); monitor.exit(this); if (iscanceled == true) break; } writer.close(); } }
Comments
Post a Comment