Recent

Author Topic: Incorrect buffering in multithread programs  (Read 12629 times)

PascalDragon

  • Hero Member
  • *****
  • Posts: 5462
  • Compiler Developer
Re: Incorrect buffering in multithread programs
« Reply #15 on: July 02, 2021, 03:13:42 pm »
Output /eventually/ maps to stdout. However while every occurrence of (per-thread) Output maps to the same (per-process) stdout you can't say the reverse since the per-thread Output files operate aynchronously (which is, after all, the whole idea of having threads).
Although I'm not a 100 percent sure (never dug into the details), I doubt that input,output files have a special treatment or separate copies for threads.

The standard I/O Text variables are simply declared as threadvar, that's all that's needed for "thread safety".

... and you had already explicitly said that there's per-thread buffering, so I suspect that somebody's posted without reading the whole topic.

It's simply per-thread buffering by the variables being declared as threadvar, because the buffer is part of the TextRec.

alpine

  • Hero Member
  • *****
  • Posts: 1061
Re: Incorrect buffering in multithread programs
« Reply #16 on: July 02, 2021, 03:55:18 pm »
Output /eventually/ maps to stdout. However while every occurrence of (per-thread) Output maps to the same (per-process) stdout you can't say the reverse since the per-thread Output files operate aynchronously (which is, after all, the whole idea of having threads).
Although I'm not a 100 percent sure (never dug into the details), I doubt that input,output files have a special treatment or separate copies for threads.

The standard I/O Text variables are simply declared as threadvar, that's all that's needed for "thread safety".

... and you had already explicitly said that there's per-thread buffering, so I suspect that somebody's posted without reading the whole topic.
As I said, not a 100% sure and I doubt...
And as long the PascalDragon posts are almost always informative and right, I find yours at times somewhat hazy and sardonic.

Now, with that threadvar clarification, I dug further in RTL to find that there is not only separate thread copies of input and output, but also additional SysInitStdIO/SysFlushStdIO at the each thread creation and cleanup.

Hope everybody will learn something new here.
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

MarkMLl

  • Hero Member
  • *****
  • Posts: 6682
Re: Incorrect buffering in multithread programs
« Reply #17 on: July 02, 2021, 04:46:47 pm »
As I said, not a 100% sure and I doubt...
And as long the PascalDragon posts are almost always informative and right, I find yours at times somewhat hazy and sardonic.

My apologies, it's the Slav in me.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018