Skip to content

AndroidParameters constructor, #1657 - #1658

Merged
devemux86 merged 1 commit into
masterfrom
param
Feb 21, 2025
Merged

devemux86 merged 1 commit into
masterfrom
param

Conversation

@devemux86

Copy link
Copy Markdown
Collaborator

No description provided.

@devemux86 devemux86 added this to the 0.24.0 milestone Feb 21, 2025
@devemux86
devemux86 merged commit d658c4f into master Feb 21, 2025
@devemux86
devemux86 deleted the param branch February 21, 2025 14:25
@Sublimis

Copy link
Copy Markdown
Contributor

This doesn't provide any benefit. It would be best to completely overhaul the parameter classes while at it; perhaps make a distinction between those parameters that are okay to change at runtime and those that should not be changed after setup. The former should be marked as volatile, the latter should be implemented as part of a factory that would create a solid immutable object.

@devemux86

Copy link
Copy Markdown
Collaborator Author

Just being the same as other similar classes. 🙂

@Sublimis

Copy link
Copy Markdown
Contributor

Hmm, sometimes it seems like we don't speak the same language 🙂 Yes, this concerns both Parameters (primarily) and AndroidParameters classeses. Are there any others?

It is not guaranteed that these parameter fields will be synchronized in any way. When someone decides to update one of the parameters during (multi-threaded) execution, they could run into troubles. That was just one of the many reasons why we asked you nicely to set 32-bit color as the default or, for example, not to use the parameter at all.

@devemux86

Copy link
Copy Markdown
Collaborator Author

Another example is the various Constants classes.


Parameters is to be set once before initializing and using the library.
Its purpose was never to be changed during the library usage.

e.g. desktop Samples

@Sublimis

Copy link
Copy Markdown
Contributor

Read this to better understand the implications of not using volatile for such fields: https://stackoverflow.com/questions/2423622/volatile-vs-static-in-java

In particular:

Even if you access a static value through multiple threads, each thread can have its local cached copy!

And:

Volatile fields are special fields which are used for communicating state between threads. Each read of a volatile will see the last write to that volatile by any thread; in effect, they are designated by the programmer as fields for which it is never acceptable to see a "stale" value as a result of caching or reordering. The compiler and runtime are prohibited from allocating them in registers. They must also ensure that after they are written, they are flushed out of the cache to main memory, so they can immediately become visible to other threads. Similarly, before a volatile field is read, the cache must be invalidated so that the value in main memory, not the local processor cache, is the one seen.

from https://www.cs.umd.edu/~pugh/java/memoryModel/jsr-133-faq.html#volatile.

Earlier we guesstimated that probably no one messes with the Parameters class in production and large-scale applications, because otherwise we'd probably see some reports of problems caused by this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants