@@ -822,7 +822,7 @@ struct Factorizer {
822822 // Sieving function
823823 void sievePolynomials (const BigInteger& low, const BigInteger& high) {
824824 const BigInteger maxLcv = toFactorSqrt + high;
825- for (BigInteger y = toFactorSqrt + 1U + low; y < maxLcv; ++y) {
825+ for (BigInteger y = toFactorSqrt + 1U + low; isIncomplete && ( y < maxLcv) ; ++y) {
826826 // Make the candidate NOT a multiple on the wheels.
827827 BigInteger candidate = forwardFn (backwardFn (y * y - toFactor));
828828 // This actually just goes ahead and FORCES
@@ -850,6 +850,7 @@ struct Factorizer {
850850 // If we have enough rows for Gaussian elimination already,
851851 // there's no reason to sieve any further.
852852 if (smoothNumberKeys.size () > rowLimit) {
853+ isIncomplete = false ;
853854 smoothNumberSet.clear ();
854855
855856 return ;
@@ -933,7 +934,7 @@ struct Factorizer {
933934 // Find a congruence of squares:
934935 auto ikit = smoothNumberKeys.begin ();
935936 auto ivit = smoothNumberValues.begin ();
936- BigInteger result;
937+ BigInteger result = 1U ;
937938 for (size_t i = 0U ; i < smoothNumberKeys.size (); ++i) {
938939 dispatch.dispatch ([this , i, ikit, ivit, &result]() -> bool {
939940 auto jkit = ikit;
@@ -954,6 +955,7 @@ struct Factorizer {
954955 // Check congruence of squares
955956 BigInteger factor = gcd (this ->toFactor , x + y);
956957 if ((factor != 1U ) && (factor != this ->toFactor )) {
958+ std::lock_guard<std::mutex> lock (this ->batchMutex );
957959 result = factor;
958960
959961 return true ;
@@ -966,6 +968,7 @@ struct Factorizer {
966968 // Try x - y as well
967969 factor = gcd (this ->toFactor , x - y);
968970 if ((factor != 1U ) && (factor != this ->toFactor )) {
971+ std::lock_guard<std::mutex> lock (this ->batchMutex );
969972 result = factor;
970973
971974 return true ;
@@ -978,7 +981,9 @@ struct Factorizer {
978981 ++ivit;
979982 }
980983
981- return 1U ;
984+ dispatch.finish ();
985+
986+ return result;
982987 }
983988
984989 // Produce a smooth number with its factorization vector.
0 commit comments