Title: Threading memory model guarantees · Issue #1425 · jruby/jruby · GitHub
Open Graph Title: Threading memory model guarantees · Issue #1425 · jruby/jruby
X Title: Threading memory model guarantees · Issue #1425 · jruby/jruby
Description: The wiki page about concurrency says that updating an object instance var is not guaranteed to be visibile to other threads, although this action is thread safe. I cannot understand how this is possible under Java Memory Model: if the up...
Open Graph Description: The wiki page about concurrency says that updating an object instance var is not guaranteed to be visibile to other threads, although this action is thread safe. I cannot understand how this is pos...
X Description: The wiki page about concurrency says that updating an object instance var is not guaranteed to be visibile to other threads, although this action is thread safe. I cannot understand how this is pos...
Opengraph URL: https://github.com/jruby/jruby/issues/1425
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Threading memory model guarantees","articleBody":"The wiki page about concurrency says that updating an object instance var is not guaranteed to be visibile to other threads, although this action is thread safe.\n\n1) I cannot understand how this is possible under Java Memory Model: if the update is thread safe, so we're using a lock or volatile variable some where, but those primitives ensure also visibility due to happens-before relation.\nAm I missing something or the wiki page is wrong?\n\nIf I'm wrong and the wiki page is right, we've a bigger problem.\n\nLook, for example, at this simple class\n\n``` ruby\nclass Counter\n def initialize\n @mutex = Mutex.new\n @value = 0\n end\n\n def increment\n @mutex.synchronize { @value = @value + 1 }\n end\n\n def value\n @mutex.synchronize { @value }\n end\n```\n\nNow, `@mutex` is set in constructor and is and instance variable, without visibility guarantees is possible that a thread sees it a `nil` when calling `increment`!\n(Java solves this issue ensuring that any final field is visible after an object is constructed, non-final field must be synchronized and we can use the implicit lock to do so or a final one)\nIn other word, to safely develop multithread code in Ruby we need at minimum to be sure that fields set in constructor are visibile at least when they are used as \"effectively final\" fields.\n\n2) if JRuby already provides that guarantee I think it should be added to the wiki page, otherwise the core should be modified to achieve this result\n\n(I've tried to look into sources and I think that JRuby already provide visibility between threads, but multihreading is very hard and it's better to be sure about those details :) ) \n","author":{"url":"https://github.com/mighe","@type":"Person","name":"mighe"},"datePublished":"2014-01-20T20:39:45Z","url":"https://github.com/jruby/jruby/issues/1425"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:801e2165-fc23-3fb7-a5fd-047307569bca |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B038:3C44C0:3C9394:50C7EB:6B037E52 |
| html-safe-nonce | 2d0c56c1bcfa3a4443d0cf5e61522332429eb02538ef7d0d73e60ef820aaa845 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMDM4OjNDNDRDMDozQzkzOTQ6NTBDN0VCOjZCMDM3RTUyIiwidmlzaXRvcl9pZCI6IjE5NzA2NjkwODQ2OTM3MjQ3NTQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f1e7bc5acc259c5d7c04d1f849c8e47e001f59d832519444d7be0f777cf65d8d |
| hovercard-subject-tag | issue:25944905 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/jruby/jruby/1425/issue_layout |
| twitter:image | https://opengraph.githubassets.com/247503594d01e0b5cfc77d4ec60475da5389f95b628e9f70d8eacd8f82836230/jruby/jruby/issues/1425 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/247503594d01e0b5cfc77d4ec60475da5389f95b628e9f70d8eacd8f82836230/jruby/jruby/issues/1425 |
| og:image:alt | The wiki page about concurrency says that updating an object instance var is not guaranteed to be visibile to other threads, although this action is thread safe. I cannot understand how this is pos... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mighe |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/jruby/jruby git https://github.com/jruby/jruby.git |
| octolytics-dimension-user_id | 55687 |
| octolytics-dimension-user_login | jruby |
| octolytics-dimension-repository_id | 168370 |
| octolytics-dimension-repository_nwo | jruby/jruby |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 168370 |
| octolytics-dimension-repository_network_root_nwo | jruby/jruby |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width