mishaturnbull/EmailGUI

Multithreading `MT-LIM` mode may sometimes spawn more threads than instructed

Closed this issue · 1 comments

In the case of a multithreading-limited configuration where the amount of emails being sent does not divide evenly by the number of threads specified, the program spawns an additional thread to send the remainder of the emails. This behavior can be summarized as follows:

Num. emails = 100
Num. threads = 14

The worker thread manager divides 100 // 14 and gets 7 emails per thread. It then detects that since 7*14 = 98, it will be short 2 emails of the desired 100. Therefore, it elects to spawn a 15th thread to send the remaining 2 emails:

Thread no.   | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15
Num. emails. | 7 | 7 | 7 | 7 | 7 | 7 | 7 | 7 | 7 | 7 |  7 |  7 |  7 |  7 |  7 |  2

This behavior should be replaced by instead increasing slightly the workload for 2 of the 14 preexisting threads, such that the number of emails sent by each thread will be as follows:

Thread no.   | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 
Num. emails. | 8 | 8 | 7 | 7 | 7 | 7 | 7 | 7 | 7 | 7 |  7 |  7 |  7 |  7 |  7 

so that the total number of emails equals 100 and the total number of threads equals 14.

This is fixed in a3a86a0. Will close when 2.x is merged into master.