亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1734 | 回復(fù): 7
打印 上一主題 下一主題

[其他] 怎么沒有C#模板。空搲锩嬗腥好? [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2015-09-11 08:22 |只看該作者 |倒序?yàn)g覽
怎么沒有C#模板?論壇里面有群么?

663de81190ef76c6028d9c1a9e16fdfaae516780.png (23.02 KB, 下載次數(shù): 53)

663de81190ef76c6028d9c1a9e16fdfaae516780.png

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2015-09-17 11:12 |只看該作者
沒人回答么?

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2015-09-17 11:13 |只看該作者
自己給自己頂!

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2015-09-17 11:14 |只看該作者
人呢?出來

論壇徽章:
0
5 [報(bào)告]
發(fā)表于 2015-09-17 11:16 |只看該作者

論壇徽章:
59
2015年亞洲杯之約旦
日期:2015-01-27 21:27:392015年亞洲杯之日本
日期:2015-02-06 22:09:41拜羊年徽章
日期:2015-03-03 16:15:432015年辭舊歲徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015元宵節(jié)徽章
日期:2015-03-06 15:50:392015年亞洲杯之阿聯(lián)酋
日期:2015-03-19 17:39:302015年亞洲杯之中國
日期:2015-03-23 18:52:23巳蛇
日期:2014-12-14 22:44:03雙子座
日期:2014-12-10 21:39:16處女座
日期:2014-12-02 08:03:17天蝎座
日期:2014-07-21 19:08:47
6 [報(bào)告]
發(fā)表于 2015-09-17 18:14 |只看該作者
有噬,  m:n線程模板
  1. // -- Multi-threads --
  2. namespace ntrt
  3. {
  4.     /// <summary>
  5.     ///     -- sample code (parallel exec with 64 threads) --
  6.     ///        ntrt.ThreadAddress<int, int> thstart = delegate(int obj)
  7.     ///        {
  8.     ///            Console.Write(string.Format("{0}\n", obj));
  9.     ///            return obj;
  10.     ///        };

  11.     ///        ntrt.ParallelThread<int, int> thrds = new ntrt.ParallelThread<int, int>();
  12.     ///        for (int iC = 0; iC < 2048; iC++)
  13.     ///        {
  14.     ///            thrds.Add(thstart, iC);
  15.     ///        }
  16.     ///        int[] rts = ntrt.ParallelThread<int, int>.wait(thrds.exec(64));   //Environment.ProcessorCount *8);
  17.     ///        Console.WriteLine("\n-------------------------------------------------");
  18.     ///        foreach(int iret in rts){
  19.     ///            Console.Write(string.Format("{0}\n",iret));
  20.     ///        }
  21.     /// </summary>
  22.     /// <typeparam name="TRET">return value type</typeparam>
  23.     /// <typeparam name="TPARAM">parameter type</typeparam>
  24.     public delegate TRET ThreadAddress<TRET, TPARAM>(TPARAM obj); // where TRET : class;
  25.     public delegate void FinishEventHandler<TRET, TPARAM>(ParallelThread<TRET, TPARAM> sender, TPARAM args, TRET ret, params object[] envs);
  26.     public class ParallelThread<TRET, TPARAM> : List<KeyValuePair<ThreadAddress<TRET, TPARAM>, TPARAM>>
  27.     {
  28.         private const int IDX_SELF = 0;
  29.         private const int IDX_NPARALLEL = 1;
  30.         private const int IDX_COUNTER = 2;
  31.         private const int IDX_RETURNS = 3;
  32.         //private const int IDX_HANDLE = 1;

  33.         public object exec(int nThread, TRET defBadRetval, params object[] envs)
  34.         {
  35.             this.isCancelled = false;
  36.             ParameterizedThreadStart inner_start = delegate (object argobj)
  37.             {
  38.                 object[] arglist = argobj as object[];
  39.                 System.Diagnostics.Debug.Assert(arglist.Length == 4);
  40.                 System.Diagnostics.Debug.Assert(arglist[IDX_SELF] is ParallelThread<TRET, TPARAM>);
  41.                 //System.Diagnostics.Debug.Assert(arglist[IDX_HANDLE] is IntPtr);
  42.                 System.Diagnostics.Debug.Assert(arglist[IDX_NPARALLEL] is int);
  43.                 System.Diagnostics.Debug.Assert(arglist[IDX_COUNTER] is InnerCounter);
  44.                 System.Diagnostics.Debug.Assert(arglist[IDX_RETURNS] is TRET[]);

  45.                 ParallelThread<TRET, TPARAM> thrds = arglist[IDX_SELF] as ParallelThread<TRET, TPARAM>;
  46.                 //IntPtr hGcHandle = (IntPtr)arglist[IDX_HANDLE];
  47.                 int nThreads = (int)arglist[IDX_NPARALLEL];
  48.                 InnerCounter counter = (InnerCounter)arglist[IDX_COUNTER];
  49.                 TRET[] retvals = arglist[IDX_RETURNS] as TRET[];
  50.                 do
  51.                 {
  52.                     int iCount = 0;
  53.                     lock (counter)
  54.                     {
  55.                         counter.iCount++;
  56.                         iCount = counter.iCount;
  57.                     }
  58.                     //int iCount = Interlocked.Increment(ref counter.iCount);   //<- C# is unreliable... :-(.

  59.                     if (iCount < counter.nCount)
  60.                     {
  61.                         if (thrds[iCount].Key != null)
  62.                         {
  63.                             retvals[iCount] = thrds[iCount].Key(thrds[iCount].Value);
  64.                             if (thrds.Onfinished != null)
  65.                             {
  66.                                 thrds.Onfinished(thrds, thrds[iCount].Value, retvals[iCount], envs);
  67.                             }
  68.                         }
  69.                     }
  70.                     else
  71.                     {
  72.                         break;
  73.                     }
  74.                 } while (this.isCancelled == false);

  75.                 int nComplete = 0;
  76.                 lock (counter)
  77.                 {
  78.                     counter.nComplete++;
  79.                     nComplete = counter.nComplete;
  80.                 }
  81.                 if (nComplete == nThreads)
  82.                 {
  83.                     if (thrds.OnCompeleted != null)
  84.                     {
  85.                         thrds.OnCompeleted(thrds, new EventArgs());
  86.                     }
  87.                 }
  88.             };

  89.             TRET[] rets = new TRET[this.Count];
  90.             for (int iRet = 0; iRet < rets.Length; iRet++)
  91.             {
  92.                 rets[iRet] = defBadRetval;
  93.             }

  94.             int nRealThread = nThread;
  95.             if (nRealThread > this.Count)
  96.             {
  97.                 nRealThread = this.Count;
  98.             }
  99.             InnerCounter ic = new InnerCounter() { iCount = -1, nComplete = 0, nCount = this.Count };
  100.             Thread[] threads = new Thread[nRealThread];
  101.             for (int iThd = 0; iThd < threads.Length; iThd++)
  102.             {
  103.                 threads[iThd] = new Thread(inner_start);
  104.                 threads[iThd].Start(new object[] { this, nRealThread, ic, rets });
  105.             }

  106.             return new object[] { rets, threads } as object;

  107.             //GCHandle gh = GCHandle.Alloc(new object[] { rets, threads });
  108.             //IntPtr hgh = GCHandle.ToIntPtr(gh);
  109.             //return hgh;
  110.         }//end function: exec

  111.         public void Add(ThreadAddress<TRET, TPARAM> thaddr, TPARAM args)
  112.         {
  113.             this.Add(new KeyValuePair<ThreadAddress<TRET, TPARAM>, TPARAM>(thaddr, args));
  114.         }
  115.         public bool isCancelled { set; get; }
  116.         public event FinishEventHandler<TRET, TPARAM> Onfinished;
  117.         public event EventHandler OnCompeleted;
  118.         public object UserData { set; get; }

  119.         // -- Helper function --
  120.         public void abort(object h)
  121.         {
  122.             object[] args = h as object[];

  123.             System.Diagnostics.Debug.Assert(args.Length == 2);
  124.             System.Diagnostics.Debug.Assert(args[0] is TRET[]);
  125.             System.Diagnostics.Debug.Assert(args[1] is Thread[]);
  126.             foreach (Thread thd in args[1] as Thread[])
  127.             {
  128.                 try
  129.                 {
  130.                     thd.Abort();
  131.                 }
  132.                 catch (Exception ex)
  133.                 {
  134.                     System.Diagnostics.Debug.Assert(ex != null);
  135.                 }
  136.             }

  137.             if (this.OnCompeleted != null)
  138.             {
  139.                 this.OnCompeleted(this, new EventArgs());
  140.             }
  141.         }
  142.         public static TRET[] wait(object h)
  143.         {
  144.             object[] args = h as object[];

  145.             System.Diagnostics.Debug.Assert(args.Length == 2);
  146.             System.Diagnostics.Debug.Assert(args[0] is TRET[]);
  147.             System.Diagnostics.Debug.Assert(args[1] is Thread[]);

  148.             Thread[] threads = args[1] as Thread[];
  149.             foreach (Thread thd in threads)
  150.             {
  151.                 thd.Join(); //<- Wait for all thread exits
  152.             }

  153.             TRET[] rets = args[0] as TRET[];
  154.             return rets;
  155.         }//end function: wait

  156.         public static int nLogicCPUCores { get { return Environment.ProcessorCount; } }
  157.         private class InnerCounter
  158.         {
  159.             public volatile int iCount = 0;
  160.             public int nCount = 0;
  161.             public volatile int nComplete = 0;
  162.         }
  163.     }//end class: class ParallelThread<TRET, TPARAM>
  164. }//end namespace: ntrt
復(fù)制代碼

論壇徽章:
1
2015年辭舊歲徽章
日期:2015-03-03 16:54:15
7 [報(bào)告]
發(fā)表于 2015-09-20 21:25 |只看該作者
c#的泛型沒啥好說的,非圖靈完備,基本就是一坨屎。沒有分支沒有賦值,神馬都玩不出來。

論壇徽章:
89
水瓶座
日期:2014-04-01 08:53:31天蝎座
日期:2014-04-01 08:53:53天秤座
日期:2014-04-01 08:54:02射手座
日期:2014-04-01 08:54:15子鼠
日期:2014-04-01 08:55:35辰龍
日期:2014-04-01 08:56:36未羊
日期:2014-04-01 08:56:27戌狗
日期:2014-04-01 08:56:13亥豬
日期:2014-04-01 08:56:02亥豬
日期:2014-04-08 08:38:58程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-01-05 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-01-07 06:20:00
8 [報(bào)告]
發(fā)表于 2015-09-21 08:52 |只看該作者
本帖最后由 fender0107401 于 2015-09-21 08:52 編輯

Unix-Like下面能寫C#嗎?
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP