If the compiler can help us with that, that is very useful. And 440bx already explained it well.
You may perceive it as "help by the compiler" => but it is not.
Is you helping the compiler (helping to optimize). Because you are telling the compiler: "foo will not change. Go ahead optimize".
And that means not to change by any means.
procedure somethnig(const foo: integer);
begin
writeln(foo);
CallSub;
inc(foo);
writeln(foo):
end;
If you call the above code with "x=1", and if "CallSub has a pointer to "x", and changes that value to -1 => then the above code has no defined behaviour.
If not optimized (as currently, since the compiler is not yet that clever) then it would print: 1 then 0 (after inc(-1))
But if optimized it would print: 1 then 2
Because the compiler would be allowed to keep a copy of the value 1 somewhere were CallSub could not reach it, and use that for optimization.
And this is exactly according to the documentation of const parameters.
And as you can see nothing to do with threads.
And btw, you do that with refcounted data (ansistring, dyn array) and you can get wrong data and crashes (with any current fpc version)
The fact that the compiler may give you an error if you try "foo := ... => is just that the compiler caught you lying. But, if you disguise that lie well enough, the compiler wont spot it. And then the result may be a program that does not behave (or may stop behaving in some future version of fpc, when the compiler gets better at optimizing)
Ok in this example "x" would be passed by value, so Callsub would need a pointer to foo.