Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

writeln is not thread-safe #55345

Closed
ntkme opened this issue Mar 31, 2024 · 2 comments
Closed

writeln is not thread-safe #55345

ntkme opened this issue Mar 31, 2024 · 2 comments
Assignees
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-io triaged Issue has been triaged by sub team type-enhancement A request for a change that isn't a bug

Comments

@ntkme
Copy link
Contributor

ntkme commented Mar 31, 2024

1d3d819 only partially fixed #53471, that the print function is now thread safe. However. stdout.writeln and stderr.writeln are still not thread safe.

stdout.writeln can be replaced with print in most cases, however, stderr.writeln does not have a thread-safe alternative.

import 'dart:isolate';
import 'dart:io';

void main() {
  Future.wait([
    for (var i = 0; i < 100; i += 1)
      Isolate.run(() {
        stdout.writeln('test');
      })
  ]);
}

@a-siva

@lrhn
Copy link
Member

lrhn commented Mar 31, 2024

Must it be?

I'd personally accept any interleaving of the characters emitted by the isolates, as long as the ones from a single isolate are in the correct order.
The Posix standard does require individual calls to be flock-ing on the FILE*, but we haven't promised that writeln is atomic, or that it's one Posix call.

If it's easy and cheap to fix, we should probably do it, just for the convenience.
If not, maybe it just needs a disclaimer.

@lrhn lrhn added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-io type-enhancement A request for a change that isn't a bug labels Mar 31, 2024
@ntkme
Copy link
Contributor Author

ntkme commented Mar 31, 2024

We already made print behave this way. I guess it shouldn't be too hard to make writeln for at least stdout and stderr behave the same way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-io triaged Issue has been triaged by sub team type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

3 participants