public WorkerQueuePrivate(ThreadProc threadProc, int numWorkerThreads, object[] tasks) { ThreadList = new List <ThreadObj>(); int i; this.ThreadProc = threadProc; this.NumWorkerThreads = numWorkerThreads; foreach (object task in tasks) { TaskQueue.Enqueue(task); } RaisedException = null; for (i = 0; i < numWorkerThreads; i++) { ThreadObj t = new ThreadObj(WorkerThread); ThreadList.Add(t); } foreach (ThreadObj t in ThreadList) { t.WaitForEnd(); } if (RaisedException != null) { throw RaisedException; } }
public static void jsonrpc_client_server_both_test() { //jsonrpc_server_invoke_test().Wait();return; // start server HttpServerOptions http_cfg = new HttpServerOptions() { DebugKestrelToConsole = false, }; JsonRpcServerConfig rpc_cfg = new JsonRpcServerConfig() { }; using (RpcServerApiTest h = new RpcServerApiTest()) using (var s = JsonRpcHttpServerBuilder.StartServer(http_cfg, rpc_cfg, h)) { Ref <bool> client_stop_flag = new Ref <bool>(); // start client ThreadObj client_thread = ThreadObj.Start(param => { //Kernel.SleepThread(-1); //using () { //c.AddHeader("X-1", "Hello"); rpctmp1 t = new rpctmp1(); t.a = new rpc_t() { Int1 = 2, Str1 = "Neko", }; //JsonRpcResponse<object> ret = c.CallOne<object>("Test1", t).Result; //JsonRpcResponse<object> ret = c.CallOne<object>("Test2", t).Result; Benchmark b = new Benchmark("rpccall"); JsonRpcHttpClient <rpc_server_api_interface_test> c = new JsonRpcHttpClient <rpc_server_api_interface_test>("http://127.0.0.1:88/rpc"); var threads = ThreadObj.StartMany(256, par => { while (client_stop_flag.Value == false) { //c.Call.Divide(8, 2).Wait(); TMP1 a = new TMP1() { a = 4, b = 2 }; c.MT_Call <object>("Divide", a, true)._GetResult(); //c.ST_CallOne<object>("Divide", a, true).Wait(); b.IncrementMe++; } } ); foreach (var thread in threads) { thread.WaitForEnd(); } //c.Call.Divide(8, 2).Result.Print(); //c.Call.Divide(8, 2).Result.Print(); //c.Call.Test3(1, 2, 3).Result.Print(); //c.Call.Test5(1, "2").Result.ObjectToJson().Print(); //var fnlist = c.Call.Test6().Result; ////foreach (var fn in fnlist) fn.Print(); //c.Call.Test7(fnlist).Result.Print(); //Con.WriteLine(ret.ObjectToJson()); } }, null); Con.ReadLine("Enter to quit>"); client_stop_flag.Set(true); client_thread.WaitForEnd(); } }
// 終了待機 public void WaitForEnd() { thread.WaitForEnd(); }