Skip to content

Commit

Permalink
fix: thread creation bug when cpus number < 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Elias-Gill committed Oct 14, 2024
1 parent e31e468 commit 3d8d1b3
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions gui/grid.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,16 @@ func newEmptyFrame(image config.Image) card {
/*
Generates the thumbnail for the card and refresh the container.
Creates as many threads as cpus-2, so the app runs faster but the
Creates as many threads as ceil(cpus/2), so the app runs faster but the
cpu does not get overwhelmed.
*/
func (c wallpapersGrid) fillContainers() {
log.Println("\n Usando ", runtime.NumCPU()-2, " Hilos")
hilos := int(runtime.NumCPU()/2)
if hilos <= 0 {
hilos = 1
}

log.Println("\n Usando ", hilos, " Hilos")

wg := sync.WaitGroup{}

Expand All @@ -115,7 +120,7 @@ func (c wallpapersGrid) fillContainers() {
}(&wg)

// generate only as many thumbnails as number of cpus-2
if k%(runtime.NumCPU()-2) == 0 {
if k%(hilos) == 0 {
wg.Wait()
}
}
Expand Down

0 comments on commit 3d8d1b3

Please sign in to comment.