You are not logged in. Your edit will be placed in a queue until it is peer reviewed.
We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.
Required fields*
-
1A problem with fine-grained locks is that it is extremely easy to produce deadlocks. For this to work efficiently and safely, there would have to be extra rules like "every thread may lock at most 1 GC object at a time" and "GC object locks must only be held for a short duration". Only the GC system itself would be exempt. But now these fine-grained locks are more like a single coarse-grained lock, and we have arrived at something like CPython's GIL.amon– amon2024-02-17 15:54:51 +00:00Commented Feb 17, 2024 at 15:54
-
I should mention since not everyone knows. Reader-writer lock is an actual thing! Such as the one defined in POSIX, as well as the one implemented in Mr Butenhof's book for illustration.DannyNiu– DannyNiu2024-02-17 23:21:38 +00:00Commented Feb 17, 2024 at 23:21
-
IIRC the writer lock cannot be acquired unless all reader locks have been released. That's kind of the point of the reader-writer lock. So i don't think the problem you're describing should occur with a properly implemented lock. However, this will also prevent you from doing the stop the world event, because the writer lock only locks when nobody is using your objects. Executing arbitrary code within locks is generally not a good idea.Ccm– Ccm2024-02-18 00:16:36 +00:00Commented Feb 18, 2024 at 0:16
-
@Ccm "writer lock cannot be acquired unless all reader locks have been released" - Yes, but will the thread acquiring the writer lock see all the changes made by threads that held reader lock? Especially on NUMA architectures? I'm asking this from a memory-order sematic point of view.DannyNiu– DannyNiu2024-02-18 00:48:19 +00:00Commented Feb 18, 2024 at 0:48
-
2I think your concern about the insufficient fence is valid, but this illustrates that the scenario is inherently unsound. (1) You want a conventional rwlock but want the "read" lock to order writes. That doesn't make sense. But you could use the same techniques as an rwlock to implement a threads-xor-gc lock that does guarantee suitable memory order. (2) You imply that objects can be shared between threads. If they modify the object without explicit synchronization, that's already unsound – regardless of GC strategy.amon– amon2024-02-18 06:49:49 +00:00Commented Feb 18, 2024 at 6:49
|
Show 3 more comments
How to Edit
- Correct minor typos or mistakes
- Clarify meaning without changing it
- Add related resources or links
- Always respect the author’s intent
- Don’t use edits to reply to the author
How to Format
-
create code fences with backticks ` or tildes ~
```
like so
``` -
add language identifier to highlight code
```python
def function(foo):
print(foo)
``` - put returns between paragraphs
- for linebreak add 2 spaces at end
- _italic_ or **bold**
- indent code by 4 spaces
- backtick escapes
`like _so_` - quote by placing > at start of line
- to make links (use https whenever possible)
<https://example.com>[example](https://example.com)<a href="https://example.com">example</a>
How to Tag
A tag is a keyword or label that categorizes your question with other, similar questions. Choose one or more (up to 5) tags that will help answerers to find and interpret your question.
- complete the sentence: my question is about...
- use tags that describe things or concepts that are essential, not incidental to your question
- favor using existing popular tags
- read the descriptions that appear below the tag
If your question is primarily about a topic for which you can't find a tag:
- combine multiple words into single-words with hyphens (e.g. design-patterns), up to a maximum of 35 characters
- creating new tags is a privilege; if you can't yet create a tag you need, then post this question without it, then ask the community to create it for you