Skip to content

ArrayBuffer concurrent write safety question #53796

Answered by mateuspaulino
Sytten asked this question in General
Discussion options

You must be logged in to vote

Hi @Sytten

Great question! When you see the Node.js code like:

char* buffer_data = Buffer::Data(buffer_obj);
size_t buffer_length = Buffer::Length(buffer_obj);

and then later:

FSReqBase* req_wrap_async = GetReqWrap(args, 5);
CHECK_NOT_NULL(req_wrap_async);
FS_ASYNC_TRACE_BEGIN0(UV_FS_READ, req_wrap_async)
AsyncCall(env, req_wrap_async, args, "read", UTF8, AfterInteger, uv_fs_read, fd, &uvbuf, 1, pos);

you might wonder about the safety concerning concurrent reads using the same ArrayBuffer. Here's what's happening:
Memory Management and Safety

Reference Counting: Node.js uses a garbage-collected environment (V8 engine). When you pass a buffer to an async libuv operation, Node.js internal…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@Sytten
Comment options

Answer selected by Sytten
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants