Forum > Unix
Console output and multithreading
zim:
Hi
Found some strange behaviour of Writeln in multithreaded app. It's a sort of debug mode (in normal operation it's all in logs), but really annoying.
While on Windows all is ok, I expected use of critical section will help on Linux also, but not helped. Is there any working solution present ?
The problem:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var Lock: TCriticalSection;procedure Log(S: String);begin Lock.Acquire; try // ... some code with log rotating and output Writeln(S); finally Lock.Release; end;end;
procedure Log is called many times from different code places, some in main thread, some from child threads.
Expected output:
log1
log2
log3
Actual output under Linux:
log1
log2
log3
Curt Carpenter:
I would guess it's down to the different line endings used by win (\r\n) and linux (just \n)
MarkMLl:
--- Quote from: Curt Carpenter on January 16, 2024, 03:12:25 pm ---I would guess it's down to the different line endings used by win (\r\n) and linux (just \n)
--- End quote ---
"Staircasing". However I've not seen that happen despite similarly having debug WriteLn()s called by multiple threads.
i) If in doubt, put a Flush(Output) immediately after the WriteLn.
ii) I've never had to use a critical section in that circumstance.
iii) Where are you creating that critical section?
iv) I /have/ seen peculiar effects if mixing references to Output and stdout.
v) The only time I've seen staircasing like that is if I've intentionally messed around with terminal properties using ioctl().
Are you, by any chance, using something like the Crt unit elsewhere in the program? It's generally frowned upon to post a mere fragment, for precisely that reason: people can't see what you're doing before you get to the problem.
MarkMLl
cdbc:
Hi
I have "Staircasing" galore!
I do use the Crt unit(+incs) and a home-made helper-unit:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---// too big, please see attachment :o) Funny thing is, it was running happy along ...and still does %)
Yesterday I installed a new kernel in my lappy, upgrade from 5.16.19 to 6.5.13 After that, It all went to H*** in a handbasket when program ends?!?
It ends ok, but back at the prompt, I can't see what I'm typing, and if I type "ls -l" (blind) + enter then the staircasing goes bananas :'(
I refuse to believe that it has to do with the kernel-upgrade. Regression to 5.16 is not an option, 'cause the new one is a lot faster :D
What to do?
Regards Benny
cdbc:
Have a look-see :D
Regards Benny
Navigation
[0] Message Index
[#] Next page