Parallel 试验

发布时间:2017-4-28 6:34:46 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"Parallel 试验 ",主要涉及到Parallel 试验 方面的内容,对于Parallel 试验 感兴趣的同学可以参考一下。

using System;using System.Collections.Concurrent;using System.Collections.Generic;using System.Diagnostics;using System.Threading;using System.Threading.Tasks;using System.Linq;using System.Collections;class CQ_EnqueueDequeuePeek{    public readonly static object lockObj = new object();    static void Main()    {        //int n=1000;        //var s1 = n + n * (n - 1) / 2;        //Console.WriteLine(s1);        //Console.WriteLine(1000*1000-s1);        //Console.ReadKey();        //return ;        CancellationTokenSource tokenSource = new CancellationTokenSource();        CancellationToken token = tokenSource.Token;        List<student> studentList = new List<student>();        for (long i = 0; i < 1000; i++)        {            var stu = new student();            stu.age = i;            stu.id = i;            studentList.Add(stu);        }        List<teacher> teacherList = new List<teacher>();        for (long i = 0; i < 1000; i++)        {            var t = new teacher();            t.id = i;            t.age = i;            teacherList.Add(t);        }        var ha = new Hashtable();         //                               262151        Action[] actionList = new Action[1000000];        ConcurrentBag<relation> relationList = new ConcurrentBag<relation>();        long index = 0;        foreach (var stu in studentList)        {            foreach (var t in teacherList)            {                actionList[index] = () =>                {                    relation re = new relation();                    var age1 = stu.age;                    var age2 = t.age;                    re.age1 = age1;                    re.age2 = age2;                    re.value = age1 * age2;                    relationList.Add(re);                    lock (ha)                    {                        if (!ha.ContainsKey(re.value))                        {                            ha.Add(re.value, re.value);                        }

上一篇:ChakraCore/JSRT使用问题汇总
下一篇:【经验】ansible 批量推送公钥

相关文章

关键词: Parallel 试验

相关评论

本站评论功能暂时取消,后续此功能例行通知。

一、不得利用本站危害国家安全、泄露国家秘密,不得侵犯国家社会集体的和公民的合法权益,不得利用本站制作、复制和传播不法有害信息!

二、互相尊重,对自己的言论和行为负责。

好贷网好贷款