in Education by
I found this book on internet: Threading in C# by Joseph Albahari. I tried its example: class ThreadTest { static void Main() { Thread t = new Thread(WriteY); // Kick off a new thread t.Start(); // running WriteY() // Simultaneously, do something on the main thread. for (int i = 0; i < 10000000; i++) Console.Write("x"); Console.ReadLine(); } static void WriteY() { for (int i = 0; i < 10000000; i++) Console.Write("y"); } } The problem is, when I run this program (I gave higher values in for loops to observe) my CPU utilization sticks to 100%. I didn't want this, I mean, is there anyway to reduce to make this program less CPU intensive? I am just new to multithreading concept so I thought I should ask in advance. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Multi-threading can improve your application if you can use multiple resources at the same time. For instance, if you have multiple core's, or multiple CPU's, I believe that the above example should perform better. Or, if you have a thread that uses the CPU, and another thread that simultaneously uses the disk for instance, it also will perform better if you use multi-threading. If however, you have one single CPU or one single core, the example above won't perform better. It will perform even worse.

Related questions

0 votes
    I found this book on internet: Threading in C# by Joseph Albahari. I tried its example: class ThreadTest ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jan 16, 2022 in Education by JackTerrance
0 votes
    Hey there Stack Overflow. I'm trying to build a testing script that should mix outputting changing ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    What is true about threading? (a) run() method calls start() method and runs the code (b) run() ... in division Multithreading of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    I am trying to understand the advantages of multiprocessing over threading. I know that multiprocessing gets around the ... same thing? Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    What is true about threading? (a) run() method calls start() method and runs the code (b) run() ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 24, 2021 in Education by JackTerrance
0 votes
    What is Multi-threading?...
asked Jun 13, 2021 in Education by Editorial Staff
0 votes
    What is this code an example of? A. null element B. self-closing tag C. improperly named element D. incorrect XML syntax...
asked Mar 10, 2023 in Technology by JackTerrance
0 votes
    What is meant by Ad-Hoc commands? Give one example....
asked Jan 28, 2023 in Technology by JackTerrance
0 votes
    Which of the following is an example of artificial intelligent agent/agents? a) Autonomous Spacecraft b) Human c) Robot d) All of the mentioned...
asked Jan 15, 2023 in Education by JackTerrance
0 votes
    Amazon EC2 Container Service is an example of ____________. A. Docker B. Polyglot persistence C. CQRS...
asked Jan 11, 2023 in Education by JackTerrance
0 votes
    Spring Boot is example of __________. A. Service Deployment B. Service registry C. Chassis Framework D. API Gateway...
asked Jan 11, 2023 in Technology by JackTerrance
0 votes
    Netflix OSS is an example of __________. A. Server-side discovery B. Client-side discovery...
asked Jan 10, 2023 in Education by JackTerrance
0 votes
    AWS Elastic Load Balancer (ELB) is an example of __________. A. Client-side discovery B. Server-side discovery...
asked Jan 10, 2023 in Education by JackTerrance
0 votes
    A local telephone network is an example of a _______ network. A. Packet switched B. Circuit switched C. Bit switched D. Line switched...
asked Jan 6, 2023 in Technology by JackTerrance
0 votes
    Susan is so beautiful; I bet she is smart too. This is an example of __________ (a) The halo effect (b) ... prophecy (d) The recency effect Please answer the above question....
asked Oct 22, 2022 in Education by JackTerrance
...