Skip to content

Make nob_default_handler work in multi-threaded or multi-process#248

Open
ChenXinyu-CHD wants to merge 1 commit into
tsoding:mainfrom
ChenXinyu-CHD:main
Open

Make nob_default_handler work in multi-threaded or multi-process#248
ChenXinyu-CHD wants to merge 1 commit into
tsoding:mainfrom
ChenXinyu-CHD:main

Conversation

@ChenXinyu-CHD

Copy link
Copy Markdown

The old implementation of nob_default_handler works well in a single‑threaded environment, but it may produce unexpected output in a multi‑process environment. For example, the following output is generated in my project:

[ERROR] [ERROR] [ERROR] Could not read file ../tests/if_else.mus.out: No such file or directoryCould not read file ../tests/invoke_extern.mus.out: No such file or directoryCould not read file ../tests/binop.mus.out: No such file or directory

This happens because nob_default_handler invokes fprintf multiple times, and another process may print something else between the multiple fprintf calls inside nob_default_handler.

To fix this issue, I use nob_temp_svprintf to generate the complete message first, and then print it with a single fprintf call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant