- activeThreads = Options["Threads"];
-
- // Dynamically allocate Thread object according to the number of
- // active threads. This avoids preallocating memory for all possible
- // threads if only few are used.
- for (int i = 0; i < MAX_THREADS; i++)
- if (i < activeThreads && !threads[i])
- threads[i] = new Thread(i);
- else if (i >= activeThreads && threads[i])
- {
- delete threads[i];
- threads[i] = NULL;
- }
+ int requested = Options["Threads"];
+
+ while (size() < requested)
+ threads.push_back(new Thread(size()));
+
+ while (size() > requested)
+ {
+ delete threads.back();
+ threads.pop_back();
+ }