On 8/12/20 6:54 AM, Paavo Helde wrote:
> 12.08.2020 13:09 Frederick Gotham kirjutas:
>> Before I begin, I have deliberately left out necessary code in order to make this as simplistic as possible (for example I've neglected to join all std::thread objects before destroying
> them).
...
> I copy-pasted the pieces in some order which compiled, fixed some syntax
> errors, added needed includes and missing thread joining. The final
> program worked without problems with two different compilers. I suspect
> the problem is in your code which you have not shown or have altered
> while posting.
It seems paradoxical, but empirically, people who post only the part of
their code that they think is relevant to the problem are very likely to
have removed the part that caused the problem.
If you can't post the entire program where you ran into your problem,
either because it's too big and complicated, or proprietary or
classified, what you should do is put together simplified version (with
any proprietary or classified features removed) that is complete and
compilable.
Most importantly, before posting your simplified version - confirm that
it still demonstrates the problem.
Sometimes it seems impossible to put together such a simplified version,
but there's a straightforward approach to systematically simplifying a
program that demonstrates a problem into a much simpler program that
still demonstrates it:
You'll need to have two copies of your code, WORK, which you do your
work on, and FAIL, which has been confirmed to fail. Initialize both of
them by copying the original program.
1. Identify a portion of WORK that should be removable without
interfering with the failure, preferably as large as possible. A good
starting candidate is all code that should have executed after the code
which produced the first symptom that something had gone wrong, but
toward the end of the process you might be stuck with removing only a
single line of code. If you can't find anything more to remove, you're
done - you should post the entire code of FAIL along with your question.
2. Remove that portion from WORK.
3. MOST IMPORTANT: check that WORK still demonstrates the problem. If it
does, replace FAIL with a copy of WORK. If not, think very carefully
about the part you just removed. You thought that it wouldn't remove the
problem, but it did - that's a very important clue. Replace WORK with a
copy of FAIL, and go back to step 1 - but make sure to remove a
different part of the program the next time, generally a smaller one.
It's quite common for people following this procedure to end up finding
the problem by themselves, because of the clues they accumulate from
changes that fixed the problem.
Once you're ready to post your simplified example, there's a few
additional facts you need to provide with your question:
1. Identify the precise tool chain you used to create the code,
including which options you chose. It's often the case that people will
be unable to duplicate your problem if they use a different tool chain
or make a different choices for one or more of the options.
2. Identify which result you expected to get. That might seem obvious to
you, but I've frequently seen people post code that contained no obvious
defect, and which produced exactly the results that I would expect it to
produce - the problem was that the person who wrote it was expecting
different results.
3. Identify the actual results you got. If at all possible, they should
be cut-and-pasted from the actual output. You don't want us to waste
time trying to figure out a typo that was introduced by you when you
retyped the output.
Warning: this process is not guaranteed to work. The worst problem I
ever used this approach on, I was only able to remove 52% of the code,
everything else I tried to remove made the problem disappear (and it was
unacceptable to deliver the code with that part removed). I was unable
to remove dependencies on three different third-party libraries. I sent
the simplified version to the help desk for the library that seemed most
relevant, and worked together with them for three months trying to track
down the problem - without success. The program still periodically fails
due to that problem.