Skip to content

Commit

Permalink
HW5 is completed. Chan
Browse files Browse the repository at this point in the history
  • Loading branch information
DimVlas committed May 25, 2024
1 parent c70c4f4 commit 0dad449
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions hw05_parallel_execution/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ func Run(tasks []Task, n, m int) error {
return ErrErrorsLimitExceeded
}

workerMaxCount := n
// если кол-во задач меньше кол-ва воркеров, ограничиваем кол-во воркеров
if len(tasks) < n {
workerMaxCount = len(tasks)
if len(tasks) < n { // если кол-во задач меньше кол-ва воркеров, ограничиваем кол-во воркеров
n = len(tasks)
}

tasksCh := make(chan Task) // канал задач.
Expand All @@ -43,7 +41,7 @@ func Run(tasks []Task, n, m int) error {
}()

// запускаем воркеры
for i := 0; i < workerMaxCount; i++ {
for i := 0; i < n; i++ {
wg.Add(1)
go doWork(&wg, tasksCh, errorCh)
}
Expand Down

0 comments on commit 0dad449

Please sign in to comment.