Note that there are some explanatory texts on larger screens.

plurals
  1. POThreads in parallel
    primarykey
    data
    text
    <p>The user user will write racing thread followed by file name at a command prompt:</p> <p><code>&gt;&gt;racing thread “file.txt”</code></p> <p>The program will create three threads, each thread will write numbers from 1 to 100 for 100 iteration in the specified file in step. The three threads must run at the same time. this is my code but only one thread from the three that works and not in a parallel way.</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Threading; using System.Threading.Tasks; namespace operating_system { class Program { static Thread racing_th, thread1, thread2, thread3; static string[] test; static void Main(string[] args) { Console.Write("Enter your commands " + "\n" + "To began press Enter "); string take; take = Console.ReadLine(); do { /////////new\\\\\\\\\\\\\\\\\ if (test[0] == "racingthread") { racing_th = new Thread(() =&gt; racingthread()); racing_th.Start(); } Console.Write("&gt;&gt;"); take = Console.ReadLine(); } while (!take.Equals("close")); } static void writing() { try { int n = 0; // var tasks = n Task&lt;int&gt;[n]; FileStream fs = new FileStream(test[1], FileMode.OpenOrCreate, FileAccess.ReadWrite); StreamWriter sw = new StreamWriter(fs); for (int i = 0; i &lt; 10; i++) { sw.Write("\n"+i); } sw.Close(); fs.Close(); } catch (Exception exp){} } static void racingthread() { //string[] ; FileStream fs = new FileStream(test[1], FileMode.Create); thread1 = new Thread(() =&gt; writing()); thread1.Start(); thread2 = new Thread(() =&gt; writing()); thread2.Start(); thread3 = new Thread(() =&gt; writing()); thread3.Start(); fs.Close(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload