<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><div>Hi,<br></div>
<pre class="defanged12-defanged3-u-article">[Cross posted on forum so if you want answer there :
<a href="http://forum.lazarus.freepascal.org/index.php/topic,30097.0.html">http://forum.lazarus.freepascal.org/index.php/topic,30097.0.html</a>]<br></pre><div>I want to make a simple and safe queue with multiple worker that do the jobs, so for example I add 10 job and have 2 worker that do the job.<br></div>
<div>For this I read <a href="http://wiki.freepascal.org/Multithreaded_Application_Tutorial">multi threading</a> and <a href="http://wiki.freepascal.org/Manager_Worker_Threads_System">queue </a>wiki and some posts like <a href="http://stackoverflow.com/questions/15027726/how-to-make-a-thread-finish-its-work-before-being-freed/15033839#15033839">this </a>and also Lazarus multi threading samples but still cant find out how to make a good structure that really work specially when I <a href="http://stackoverflow.com/questions/15622261/multi-thread-delphi">read </a>about that it is not very good to do counting and micro-managing.<br></div>
<div>Also I dont know a good multi threading library in Lazarus like OmniThreadLibrary and also couldn't find any good example.<br></div>
<div> </div>
<div>For now I have a list of jobs and 2 workers and also a var that control that when a thread finish start another for the next job but it not do job very good and sometimes it will mess the list of jobs.<br></div>
<div> </div>
<div>var<br></div>
<div> i: integer;<br></div>
<div>begin<br></div>
<div> try<br></div>
<div> MyCriticalSection.Enter;<br></div>
<div> for i := 0 to Count - 1 do<br></div>
<div> begin<br></div>
<div> if (StartedCount >= WorkersCount) then //check for is there need for making new thread or not<br></div>
<div> Exit;<br></div>
<div> if (not Jobs[i].Working) and (not Jobs[i].Finished) then //check the job is already done or not<br></div>
<div> StartJob(Jobs[i]);<br></div>
<div> end;<br></div>
<div> if (StartedCount = 0) then<br></div>
<div> Finish;//It will finish that list of jobs<br></div>
<div> finally<br></div>
<div> MyCriticalSection.Leave;<br></div>
<div> end; <br></div>
<div> </div>
<div>Regards,<br></div>
<div>Ara<br></div>
<pre>
--
http://www.fastmail.com - Access all of your messages and folders
wherever you are
</pre>
</body>
</html>