Skip to content

Commit

Permalink
Make CoreIO thread-safer
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyichao committed May 15, 2017
1 parent 8518fcb commit b50cf23
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/jl_uv.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ JL_DLLEXPORT int jl_fs_write(int handle, const char *data, size_t len,
int64_t offset)
{
jl_ptls_t ptls = jl_get_ptls_states();
if (ptls->safe_restore)
if (ptls->safe_restore || ptls->tid != 0)
return write(handle, data, len);
uv_fs_t req;
uv_buf_t buf[1];
Expand Down Expand Up @@ -443,6 +443,17 @@ JL_DLLEXPORT void jl_uv_puts(uv_stream_t *stream, const char *str, size_t n)
fd = ((jl_uv_file_t*)stream)->file;
}

// Hack to make CoreIO thread-safer
jl_ptls_t ptls = jl_get_ptls_states();
if (ptls->tid != 0) {
if (stream == JL_STDOUT) {
fd = STDOUT_FILENO;
}
else if (stream == JL_STDERR) {
fd = STDERR_FILENO;
}
}

if (fd) {
// Write to file descriptor...
jl_fs_write(fd, str, n, -1);
Expand Down

0 comments on commit b50cf23

Please sign in to comment.