Processing tasks with multi-core processors

Source: Internet
Author: User

1  //record when the processing started2Stopwatch Paddingtime =NewStopwatch ();3 Paddingtime.start ();4Jobhelper Jobhelper =NewJobhelper ();5             intOrderCount =Jobhelper.getjobcount ();6mutex=NewMutex (false,"Cnblogs.emulationsystem");7             if(!mutex. WaitOne (0,false))8             {9Console.Out.WriteLine ("Monitor already running ...");Ten                 return; One             } A             //TaskList (OrderCount, jobhelper); -             intMaxpronumber = -; -             using(_semaphorelimit=NewSemaphore (0, Maxpronumber)) the             { -                 //exits the semaphore at a specified number of times and returns the previous count - _semaphorelimit.release (maxpronumber); -                 varTaskList =NewList<task>(); +                  for(inti =0; i < OrderCount; i++) -                 { +                     inttemp =i; A                     //if Submitjob has IO or other exceptions that can easily be caused by a conflict, you need to add lock at                     //Lock (Lockerobj) -                     //{ - _semaphorelimit.waitone (); -Tasklist.add (Task.Factory.StartNew () = -                     { - jobhelper.submitjob (temp); in                         //exits the semaphore and returns the previous count -                         if(_semaphorelimit! =NULL) _semaphorelimit.release (); to                     })); +                     //} -                 } the Task.waitall (Tasklist.toarray ()); *             } $ paddingtime.stop ();Panax Notoginseng             varTime =paddingtime.elapsedmilliseconds; -Console.WriteLine (string. Format ("Complete : {0}, cost {1} ms", Ordercount,time));
1    Public classJobhelper2     {3          Public intGetjobcount ()4         {5             return  -;6         }7 8          Public BOOLSubmitJob (intjobId)9         {TenThread.Sleep ( +); One             return true; A         } -}

Processing tasks with multi-core processors

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.