tag:blogger.com,1999:blog-4177053433240488765.post1899043711676839304..comments2024-03-28T23:06:43.464+01:00Comments on Coding time - Martin Konicek: Implement your own Parallel.For in C#Martin Konicekhttp://www.blogger.com/profile/13169352488655771114noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-4177053433240488765.post-44640869393500896652019-12-21T21:07:42.317+01:002019-12-21T21:07:42.317+01:00have a look at bit, 5 bit of, 6 small tens. https:...have a look at bit, 5 bit of, 6 small tens. <a href="https://imgur.com/a/PA5esbP" rel="nofollow">https://imgur.com/a/PA5esbP</a> <a href="https://imgur.com/a/Sv4XuMF" rel="nofollow">https://imgur.com/a/Sv4XuMF</a> <a href="https://imgur.com/a/CADoHta" rel="nofollow">https://imgur.com/a/CADoHta</a> <a href="https://imgur.com/a/PQsSYr3" rel="nofollow">https://imgur.com/a/PQsSYr3</a> <a href="https://imgur.com/a/RZZHbW6" rel="nofollow">https://imgur.com/a/RZZHbW6</a> <a href="https://imgur.com/a/x4b1RnY" rel="nofollow">https://imgur.com/a/x4b1RnY</a> <a href="https://imgur.com/a/e4cE6wJ" rel="nofollow">https://imgur.com/a/e4cE6wJ</a>Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4177053433240488765.post-1770823000850850632017-05-30T04:52:55.096+02:002017-05-30T04:52:55.096+02:00This does not compile in .NET 3.5, because process...This does not compile in .NET 3.5, because process cannot be declared a var. I'm unfamiliar enough with delegates to not know what it's type should be to avoid this error.Alexnoreply@blogger.comtag:blogger.com,1999:blog-4177053433240488765.post-90687327038660523552013-06-28T14:30:38.976+02:002013-06-28T14:30:38.976+02:00Nice post very helpful
dbakingsNice post very helpful<br /><br /><a href="http://dbakings.com/CSharp/csharpforloopforeachloop.aspx" rel="nofollow">dbakings</a>Anonymoushttps://www.blogger.com/profile/14178155909391788234noreply@blogger.comtag:blogger.com,1999:blog-4177053433240488765.post-52238215305974927252012-02-12T14:58:51.370+01:002012-02-12T14:58:51.370+01:00There is an error in the code. The parameter shoul...There is an error in the code. The parameter should be an Action because you take an int as parameter. As wel var process = delegate() won't compile here. Had to change it to Action process = delegate(). Anyway, you helped me out! Thanks!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4177053433240488765.post-53194087570691468982010-03-24T14:29:05.981+01:002010-03-24T14:29:05.981+01:00Hello,
I love your post on the Parallel.For.
Imp...Hello,<br /> <br />I love your post on the Parallel.For.<br />Implemented as a test on a project I'm developing on a Windows Services.<br /> <br />I'm having some problems because the service scans a SQL database table and returns aproximadamento some 2 million records, then it performs some actions and finally it writes the result of operation fied in a text file.<br /> <br />Looking at the text file I realized that it works well but some records are compromised because some threads try to write the file while the value of the record is wrong.<br /> <br />How can I do to allow a result to be written on the bench only after a thread may have finished writing?<br /> <br />It is worth observing that I'm using a server with 16 processing cores.<br /><br />Part code:<br /><br />//Cria arquivo de log<br />FileStream fs = new FileStream("C:\\Logs\\001_log.txt", FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);<br />StreamWriter fp = new StreamWriter(fs);<br /><br />Parallel.For(0, table.Rows.Count, (k) =><br />{<br />try<br />{<br />Int32 iReturn = ProcRegister((Int32)table.Rows[0][0]);<br />fp.WriteLine(iReturn);<br />fp.Flush();<br />}<br />catch{}<br />finally{}<br />});<br /><br />fp.Close();<br />fp.Dispose();<br />fs.Dispose();<br />fs.Close();<br /><br />Part of the log file with problem:<br /><br />...<br />985217<br />991848<br />985680<br />988684<br />989989<br />983342<br />7367 983342 <---<br />7367 983342 <---<br />7367 <---<br />984540<br />986244<br />986016<br />984964<br />991237<br />...Rogerio Perezhttp://www.layerdev.com.brnoreply@blogger.comtag:blogger.com,1999:blog-4177053433240488765.post-3088798276536798052010-01-21T01:54:14.944+01:002010-01-21T01:54:14.944+01:00Wouldn't it be easier to just use ThreadPool i...Wouldn't it be easier to just use ThreadPool instead of manually reimplementing it? (http://msdn.microsoft.com/en-us/library/system.threading.threadpool.aspx)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4177053433240488765.post-51000672338771566462010-01-21T00:56:42.209+01:002010-01-21T00:56:42.209+01:00Why are you locking on typeof(Parallel)? You shoul...Why are you locking on typeof(Parallel)? You should just create an instance of Object in the For setup code and use that as your lock for all the parallel workers. As a result you'd be able to execute two Parallel.Fors at once without contending, also. Locking on types is not a good idea.Kevin Gaddhttps://www.blogger.com/profile/04689186557672996705noreply@blogger.comtag:blogger.com,1999:blog-4177053433240488765.post-2287222289796875012010-01-20T09:14:56.653+01:002010-01-20T09:14:56.653+01:00Thanks! I've used it here http://alicebobandma...Thanks! I've used it here http://alicebobandmallory.com/articles/2010/01/14/prime-factorization-in-parallelJonas Elfströmhttps://www.blogger.com/profile/18088865137364783994noreply@blogger.com