#Are parallel writes to unique indices of a Dynamic Buffer from multiple jobs thread safe?

1 messages · Page 1 of 1 (latest)

sage glacier
#

That title may be setting off alarm bells, because there aren’t many good reasons to want to do this. But please put that concern on the back burner for the moment…

If I have two jobs running parallel, and both of them write to the same Dynamic Buffer (but always to unique indices of that buffer), is that thread safe?

Does writing to a Dynamic Buffer index only alter that spot in ram? Or does writing to any part of the DB overwrite the entire DB?

Many thanks!

sharp jungle
#

"Does writing to a Dynamic Buffer index only alter that spot in ram?" - Yes

#

"does writing to any part of the DB overwrite the entire DB?" - No

#

"Are parallel writes to unique indices of a Dynamic Buffer from multiple jobs thread safe?" - Yes

sage glacier
#

Thank you!

acoustic trellis
#

There is a trick though as you can't easily access db in parallel (unless you pass it in a field)

sage glacier
#

Ty. What is the trick? Or is that the trick (passing it in a field)?

acoustic trellis
#

I actually meant that this is tricky

#

Don't see a way to access same db in parallel job without disabling safety and writing custom lookup mechanism

sage glacier
#

One way to do it is to schedule multiple writing jobs from the same system. Grab a BufferAccessor<T> once on the main thread, and then pass it to each job before scheduling them.