Показать сообщение отдельно
  #5  
Старый 17.12.2013, 21:03
Аватар для Bargest
Bargest Bargest вне форума
Профессионал
 
Регистрация: 19.10.2010
Адрес: Москва
Сообщения: 2,390
Версия Delphi: XE3/VS12/FASM
Репутация: 14665
По умолчанию

Небольшое дополнение.
Код:
while (enp=false) do //Ожидание окончание всех потоков
  begin
  enp:=ther[0].Finished;
  if itc>1 then for it := 2 to itc do enp:=(enp and ther[it-1].Finished);
  end;
Было бы логичней
Код:
do
  enp = true;
  for it := 0 to itc - 1 do
    enp := enp and ther[it].Finished;
while (enp = false)
Ну и IF-ы в составлении потоков можно и убрать:
Код:
ther[it-1].kss:=(it-1)*(kg mod itc);
ther[it-1].ke:=(it)*(kg mod itc) - 1;
После чего этот цикл тоже перевести на 0 to itc-1 и повысить читаемость, убрав все -1 и добавив в одном месте +1.
Код:
for it := 0 to itc-1 do
  begin
  ther[it]:= Rasch.Create(true);
  ther[it].FreeOnTerminate := true;
  ther[it].kss:=it*(kg mod itc);
  ther[it].ke:=(it + 1)*(kg mod itc) - 1;
  ther[it].proc:=rasc1;
  ther[it].start;
end;
Проще читается как-то.
ЗЫЖ если я правильно помню, при выставленном FreeOnTerminate поток по завершении самоуничтожается, а ты после этого его флаги читаешь. Не гут.
Цитата:
Сообщение от Спеки Embarcadero
Warning: When FreeOnTerminate is true, the Execute method may run and then free the thread before your application can execute the next line of code. Thus, you should not call any methods of the thread object when FreeOnTerminate is true unless you create the thread in a suspended state. FreeOnTerminate is best left for threads that simply perform a task and then naturally terminate. If you want to communicate with the thread or otherwise interact with it, including telling it when to terminate, FreeOnTerminate should never be used.
__________________
jmp $ ; Happy End!
The Cake Is A Lie.
Ответить с цитированием