More Twin Primes
Modify your previous program so that when a program is found, it stores the first number in an twin prime in a list L1 and the second number in another list L2. (Just use STL lists.)
After the for loop, in a non-parallel region, print out the list of twin primes you found. Your output might look like:
If you peruse the output, you might come across some numbers that are not paired correctly. In the sample output above, 113717 and 113719 are in L1 and L2 respectively, but the are not in the same positions. This is because several threads were attempting to write in L1 and L2. Your program might even crash.
You must guarantee that when a thread inserts a number in L1, no other thread is trying to modify L2. This is easily handled by designating some lines of code as "critical". Here is one way:
Modify your previous program by designating some sections of code "critical". Run your program a few times just to be safe.