Question

C 155 (d 105.5 4. The following is apiece of C# code. Explain what it will do. using System using System.Collections.Generic; using System.Ling using System.Text using System. Threading.Tasks using System.Threading Inamespace testThreading class Program static Thread[] threads new Thread[10] static Semaphore sem new Semaphore(3, 3) static void Csharpcorner() Console.iriteline( o is waiting in line... , Thread.Current Thread.None) sem.Waitone); Thread.Current Thread. Name); Console.Mriteline( (o enters the C-sharpcorner!, Thread.Sleep(38e); Console.kiriteline((e) is leaving the C_sharpcorner, Thread.Current sem.Release); static void Main(stringt] args) for (int i -e; iく10; i++) threads[i] new Thread(C sharpcorner); threads[i].Name thread_; threads[i].Start) Console.Read)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

This code simply describe the working of Semaphore .

Semaphore class is instanciated using

static Semaphore sem = new Semaphore(3, 3);

It takes two arguments

The first is initial number of resources(at the time of object creation). The second is the maximum number of slots available.

Before entring to critical section ,

sem.WaitOne(); is called .

and after leaving the critical section

sem.Release(); is called .

Add a comment
Know the answer?
Add Answer to:
C 155 (d 105.5 4. The following is apiece of C# code. Explain what it will...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. Analyze the following code: public class Test implements Runnable { public static void main(String[] args) { Thread t = new Thread(this); t.start(); } public void run() { System....

    1. Analyze the following code: public class Test implements Runnable { public static void main(String[] args) { Thread t = new Thread(this); t.start(); } public void run() { System.out.println("test"); } } 1. The code compiles but will not print anything since t does not invoke the run method. 2. The code will not compile since you cannot invoke "this" in a static method. 3. The program compiles, runs, and prints tests on the console. 2. What will the following example...

  • Please help with Java test questions, I will post the rest of the question in separate...

    Please help with Java test questions, I will post the rest of the question in separate post. Question 1 Consider the following program: public class CountDownApp3 {     public static void main(String[] args)     {         Thread t1 = new CountDown();         Thread t2 = new CountDown();         t1.start();         t2.start();     } } Assuming that the CountDown class extends the Thread class, how many threads are used to run this program? a. 3 b. 2 c. 4 d. 1...

  • Could anybody give me comment here to help me understand this code? please, I want details...

    Could anybody give me comment here to help me understand this code? please, I want details comment. thank you in advance using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Framing { class Program { static void Main(string[] args) { Dictionary charEncoding = new Dictionary(); charEncoding.Add("A", "01000111"); charEncoding.Add("B", "11100011"); charEncoding.Add("C", "11000001"); charEncoding.Add("ESC", "11100000"); charEncoding.Add("FLAG", "01111110"); Console.WriteLine("Enter Sequence: "); string input = Console.ReadLine().Trim().ToUpper(); Console.Write("Byte count: " + Convert.ToString((input.Split(' ').Length + 1), 2).PadLeft(8, '0')); foreach (string str in input.Split(' '))...

  • You must first compile both .cs file into .exe. Then, run the server in one command...

    You must first compile both .cs file into .exe. Then, run the server in one command prompt window and run two cilents, each in a separate command prompt window. To quit a client, you may enter no book title but just hit the enter or enter Ctrl-C. The server always displays a message whenever a client is connected and disconnected. <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key = "U101" value="PHYSICS"/> <add key = "U102" value="EDU"/> <add key = "U103"...

  • Consider the following codes: public class TestThread extends Thread {     public static void main(String[] args)...

    Consider the following codes: public class TestThread extends Thread {     public static void main(String[] args) {         TestThread thread = new TestThread();     }     @Override     public void run() {         printMyName();     }     private void printMyName() {         System.out.println("Thread is running");     } } Test Stem / Question Choices 1: What method should you invoke to start the thread TestThread? A: start() B: run() C: No. Thread will run automatically when executed. D: TestThread is not...

  • 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 namespace ConsoleApplication1 6...

    1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 namespace ConsoleApplication1 6 { class Program { 9 static void Main(string[] args) 10 { 11 test t = new test(10); Console.WriteLine(t. Getio); Console.WriteLine(t.J); 14 } 15 } 16 class test 17 { 18 18 private int i; 19 private int j; 20 public test(int a) 21 { 22 i = a; 23 j = a +5; public int Getio return i; } public int ) 29 30...

  • ==Modify the M8B by using C#== using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;...

    ==Modify the M8B by using C#== using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace M8B {     class Magic8Ball     {         static void Main(string[] args)         {             string question;             Console.WriteLine("I am the Magic 8-ball! Ask me a question and I will give you an answer.");             Console.Write("Your question: ");             question = Console.ReadLine();             Console.WriteLine("\nLet me part the mists of the time for you.");             Random rnd = new Random();             int roll =...

  • C# Visual Studio using System; using System.Collections.Generic; using System.Text; 1. Modify the program to output that...

    C# Visual Studio using System; using System.Collections.Generic; using System.Text; 1. Modify the program to output that line N times. That is, output a square of N lines each with N characters. Example output for parameters N=5 and S="*" should appear as follows: 多多本事事 串串串串串 事事事串串 事事事事事 2. Modify the DrawChars method so that the number of the line appears at that position within the line. That is, line i must have N-1 copies of S with the additional character in...

  • 1. The first task in this assignment creates the pid manager whose implementation can simply be...

    1. The first task in this assignment creates the pid manager whose implementation can simply be a single class. Of course, you can create any other classes you might need to implement the pid manager. You may use any data structure of your choice to represent the availability of process identifiers. One strategy adopts Linux’s approach of a bitmap in which a value of 0 at position i indicates that a process id of value i is available and a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT