RFR: 8356173: Remove ThreadCritical

Thomas Stuefe stuefe at openjdk.org
Fri May 9 16:55:54 UTC 2025


On Fri, 9 May 2025 16:50:00 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:

>> I added the initialization of the mutex after os::init().  Assuming that pthread_mutex will be initialized at that point.
>
> @coleenp But surely one can statically allocate a pthread_mutex_t and assign PTHREAD_MUTEX_INITIALIZER, no? I mean that's Unix 101. MacOS should be able to do that at least.
> 
> Looking at PlatformMutex, maybe it is not the right tool for the job. One needs a simple stupid mutex class like this:
> 
> 
> struct SimpleMutex {
>     pthread_mutex_t _m;
>     SimpleMutex() : _m(PTHREAD_MUTEX_INITIALIZER) {}
>     lock() -> do pthread_mutex_lock
>     unlock() -> do pthread_mutex_unlock
> };
> static SimpleMutex mymutex;
> 
> 
> etc.

Note that such a simple solution would also reduce the number of indirections when using this mutex. One less pointer load, one less memory access.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/25072#discussion_r2082105243


More information about the hotspot-dev mailing list