Hi, [Cross posted on forum so if you want answer there : http://forum.lazarus.freepascal.org/index.php/topic,30097.0.html] 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. For this I read multi threading[1] and queue [2]wiki and some posts like this [3]and also Lazarus multi threading samples but still cant find out how to make a good structure that really work specially when I read [4]about that it is not very good to do counting and micro-managing. Also I dont know a good multi threading library in Lazarus like OmniThreadLibrary and also couldn't find any good example.
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. var i: integer; begin try MyCriticalSection.Enter; for i := 0 to Count - 1 do begin if (StartedCount >= WorkersCount) then //check for is there need for making new thread or not Exit; if (not Jobs[i].Working) and (not Jobs[i].Finished) then //check the job is already done or not StartJob(Jobs[i]); end; if (StartedCount = 0) then Finish;//It will finish that list of jobs finally MyCriticalSection.Leave; end; Regards, Ara Links: 1. http://wiki.freepascal.org/Multithreaded_Application_Tutorial 2. http://wiki.freepascal.org/Manager_Worker_Threads_System 3. http://stackoverflow.com/questions/15027726/how-to-make-a-thread-finish-its-work-before-being-freed/15033839#15033839 4. http://stackoverflow.com/questions/15622261/multi-thread-delphi -- http://www.fastmail.com - Access all of your messages and folders wherever you are
-- _______________________________________________ Lazarus mailing list [email protected] http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
