public static void nodeThreadQueueMain(Object obj)
        {
            ThreadStartInfo info = (ThreadStartInfo)obj;

            MwsrThreadQueue      queue = getInstance().createQueueForCurrentThread();
            ThreadQueueProcessor proc  = new ThreadQueueProcessor(queue);

            foreach (INodeFactory each in info.factories)
            {
                NodeBase node = each.create();
                int      ix   = proc.addNode(node);

                ThreadQueuePostman postMan = new ThreadQueuePostman(queue, ix);

                SlotIdx      idx_;
                UInt64       id_       = info.gmq.add(node.getNodeName(), postMan, out idx_);
                GMQTransport transport = new GMQTransport(info.gmq, node.getNodeName(), idx_, id_);


                node.initPlatform(info.platform);
                node.initTransport(transport);
            }

            proc.init();
            proc.run();
        }
Example #2
0
            /// <summary>Executes the asynchronous pruning</summary>
            /// <param name="state">Not used</param>
            private void run(object state)
            {
                if (state != null)
                {
                    ThreadStartInfo startInfo = state as ThreadStartInfo;
                    try {
                        this.particleSystem.update(this.updates, startInfo.Start, startInfo.Count);
                    }
                    catch (Exception exception) {
                        this.exception = exception;
                    }
                }

                // If we're the final thread coming around, set the async result to finished
                int completedUpdates = Interlocked.Increment(ref this.completedUpdates);

                if (completedUpdates >= this.threads)
                {
                    this.running = false;
                    AsyncCallback callbackCopy;
                    lock (this) {
                        callbackCopy   = this.callback;
                        this.completed = true;
                        if (this.doneEvent != null)
                        {
                            this.doneEvent.Set();
                        }
                    }
                    if (callbackCopy != null)
                    {
                        callbackCopy(this);
                    }
                }
            }
        public static void runNodeInThisThread(IPlatformSupport platform, GMQueue gmq, INodeFactory factory)
        {
            ThreadStartInfo info = new ThreadStartInfo();

            info.platform  = platform;
            info.gmq       = gmq;
            info.factories = new INodeFactory[] { factory };

            nodeThreadQueueMain(info);
        }
        public static void runNodeInAnotherThread(IPlatformSupport platform, GMQueue gmq, INodeFactory factory)
        {
            ThreadStartInfo info = new ThreadStartInfo();

            info.platform  = platform;
            info.gmq       = gmq;
            info.factories = new INodeFactory[] { factory };

            Thread th = new Thread(nodeThreadQueueMain);

            th.Start(info);
        }
Example #5
0
        public static void ServerThread(object obj)
        {
            ThreadStartInfo threadStartInfo = (ThreadStartInfo)obj;
            int             startPoint      = threadStartInfo.getStartPoint();
            int             endPoint        = threadStartInfo.getEndPoint();

            Console.WriteLine($"start {startPoint} end {endPoint}");
            NamedPipeServerStream pipeServer = pipes[0];

            pipes.RemoveAt(0);
            //pipeServer.WaitForPipeDrain
            //NamedPipeServerStream pipeServer = new NamedPipeServerStream("mytestpipe", PipeDirection.InOut, numThreads);
            Console.WriteLine("[Server] Pipe created {0}", pipeServer.GetHashCode());
            pipeServer.WaitForConnection();
            Console.WriteLine("[Server] Pipe connection established");
            StreamWriter sw = new StreamWriter(pipeServer);
            StreamReader sr = new StreamReader(pipeServer);

            using (var mutex = new Mutex(false, "MyMutex1"))
            {
                for (int i = startPoint; i <= endPoint; i++)
                {
                    try
                    {
                        sw.WriteLine(Values[i]);//закончил здесь, надо передать все числа процессу
                        sw.Flush();
                    }
                    catch (IOException e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
                sw.WriteLine("");
                sw.Flush();
                string input = sr.ReadLine();
                Console.WriteLine($"переданная сумма {input}");
                double sum = Convert.ToDouble(input);
                Console.WriteLine($"сумма = {sum}");
                mutex.WaitOne();
                Results.AddResult(sum);
                Console.WriteLine($"Добавили сумму {sum}");
                mutex.ReleaseMutex();
            }
            //pipeServer.Close();
            Console.WriteLine("Connection lost");
        }
Example #6
0
 static void ComputeDxStart()
 {
     Thread[] servers = new Thread[numThreads];
     for (int i = 0; i < numThreads; i++)
     {
         var numOfThread = i;
         NamedPipeServerStream pipeServer = new NamedPipeServerStream("mytestpipe" + numOfThread.ToString(), PipeDirection.InOut, numThreads);
         pipes.Add(pipeServer);
         int             dimension       = Size / numThreads;
         int             startPoint      = i * dimension;
         int             endPoint        = startPoint + dimension - 1;
         ThreadStartInfo threadStartInfo = new ThreadStartInfo(startPoint, endPoint);
         servers[i] = new Thread((new ParameterizedThreadStart(ServerThread)));
         servers[i].Start(threadStartInfo);
     }
     Thread.Sleep(1000);
     for (int j = 0; j < numThreads; j++)
     {
         var     numOfThread = j; // номер потока связанного с создаваемым процессом
         Process process     = new Process();
         process.StartInfo.FileName = Process.GetCurrentProcess().MainModule.ModuleName;
         Console.WriteLine(Process.GetCurrentProcess().MainModule.ModuleName);
         if (numOfStep == 1)
         {
             process.StartInfo.Arguments = $"{numOfThread} {numOfStep}";
         }
         else
         {
             process.StartInfo.Arguments = $"{numOfThread} {numOfStep} {mx}";
         }
         process.StartInfo.CreateNoWindow  = false;
         process.StartInfo.UseShellExecute = true;
         process.EnableRaisingEvents       = true;
         process.Exited += ProcessOnExited;
         processes.Add(process);
     }
     foreach (var pr in processes)
     {
         pr.Start();
     }
 }
Example #7
0
        public static void ServerProcess()
        {
            //запускаю 10 потока-сервера, каждый из которых работает с 1 клиентом
            int i;

            Console.WriteLine("Введите кол-во элементов выборки");
            Size = Convert.ToInt32(Console.ReadLine());
            int dimension = Size / numThreads;

            Results = new ResultsList(); //хранит результаты сумм
            Thread[] servers = new Thread[numThreads];
            pipes = new List <NamedPipeServerStream>();
            string   writePath = "C:\\Users\\user\\source\\repos\\PipeTest\\data.txt";
            FileInfo file1     = new FileInfo(writePath);

            if (file1.Exists)
            {
                try
                {
                    using (StreamReader sr = new StreamReader(writePath, System.Text.Encoding.Default))
                    {
                        string line;
                        while ((line = sr.ReadLine()) != null)
                        {
                            int val = Convert.ToInt32(line);
                            Values.Add(val);//new
                        }
                    }
                }
                catch (IOException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            else
            {
                Values = new List <int>();
                Random rand = new Random();
                for (int j = 0; j < Size; j++)
                {
                    Values.Add(rand.Next(1, 1000));
                }
            }
            for (i = 0; i < numThreads; i++)
            {
                var numOfThread = i;
                NamedPipeServerStream pipeServer = new NamedPipeServerStream("mytestpipe" + numOfThread.ToString(), PipeDirection.InOut, numThreads);
                pipes.Add(pipeServer);
                int             startPoint      = i * dimension;
                int             endPoint        = startPoint + dimension - 1;
                ThreadStartInfo threadStartInfo = new ThreadStartInfo(startPoint, endPoint);
                servers[i] = new Thread((new ParameterizedThreadStart(ServerThread)));
                servers[i].Start(threadStartInfo);
            }
            Thread.Sleep(1000);
            for (int j = 0; j < numThreads; j++)
            {
                var     numOfThread = j; // номер потока связанного с создаваемым процессом
                Process process     = new Process();
                process.StartInfo.FileName = Process.GetCurrentProcess().MainModule.ModuleName;
                Console.WriteLine(Process.GetCurrentProcess().MainModule.ModuleName);
                int startPoint = j * dimension;
                int endPoint   = startPoint + dimension - 1;
                if (numOfStep == 1)
                {
                    process.StartInfo.Arguments = $"{numOfThread} {numOfStep}";
                }
                else
                {
                    process.StartInfo.Arguments = $"{numOfThread} {numOfStep} {mx}";
                }
                process.StartInfo.CreateNoWindow  = false;
                process.StartInfo.UseShellExecute = true;
                process.EnableRaisingEvents       = true;
                process.Exited += ProcessOnExited;
                processes.Add(process);
            }
            foreach (var pr in processes)
            {
                pr.Start();
            }
            while (i > 0)
            {
                for (int j = 0; j < numThreads; j++)
                {
                    if (servers[j] != null)
                    {
                        if (servers[j].Join(1000)) // если завершился j-ий поток или через 250 мс
                        {
                            Console.WriteLine("Server thread[{0}] finished.", servers[j].ManagedThreadId);
                            servers[j] = null;
                            i--;    // decrement the thread watch count
                        }
                    }
                }
            }
            Console.WriteLine("\nServer threads exhausted, exiting.");
            Console.ReadKey();
        }