[LDPE] 1.8.82 Released (un-inline / subfile link shortcut / zip-export)


Technical details of the Edger2 sync problem (its complicated)
#3
(2024-07-15, 11:14)Magnus Forsberg Wrote: Everytime I run Edger2 I end up in a state where I have to save the file, before any other editing is possible.

Thanks, Magnus.
Willy reported the same problem a while ago. It was unclear why, until today. It will be fixed with the next version.
The root cause was, that the UI thread did not set a boolean variable to true sometimes on some machines.

In the code you will find a function syncWithTextEditors.
What is does in simple words: It tells
Quote:"Hey, here is an update for the text editor to display. I locked the editor for changes until the update shows up."

then another process will accept the order:
Quote:"Ok. I will wait for 2.2 seconds and update the text editor, unless there is another update in the queue. Then I return that the text editor was updated and this will unlock the text editor (updated = true)."

On some machines, the response "updated = true" did not reach its destination.
This led to a state where the text editor content was updated, but it was not flagged as updated.
Then the text editor remained read only, unless you did a save for example.

The fix was implemented by adding a volatile keyword on the updated boolean variable.
Using volatile makes sure that changes on this variable are visible to every thread.

Code:
// The following line is wrong // private boolean updated = true; // This is correct, using volatile to make sure that changes are visible to every thread. private volatile boolean updated = true; public final void syncWithTextEditors(...) {     // Indicate that the text editor needs an update and should not be changed by user input     setUpdated(false);     lock.lock();     try {         Thread.ofVirtual().start(() -> {             * some higher magic in another thread *             Display.getDefault().asyncExec(() -> {                 try {                     * update the text editor in the UI thread *                 } finally {                     // The text editor was updated and is unlocked.                     // On some machines, this code did not update the value, because "volatile" was missing on the "updated" variable.                     setUpdated(true);                 }             });         });     } finally {         lock.unlock();     } }
Reply
« Next Oldest | Next Newest »



Messages In This Thread
Technical details of the Edger2 sync problem (its complicated) - by Nils Schmidt - 2024-07-15, 18:57

Forum Jump:


Users browsing this thread: 1 Guest(s)