-
Notifications
You must be signed in to change notification settings - Fork 192
Synchronization issue in Synchronizer #3151
Description
Describe the bug
There is a synchronization issue in Synchronizer.addLast().
There is no synchronization between the calls messages.isEmpty() and messages.add().
This can lead to a situation where:
- messages isEmpty() returns false,
- the consuming side empties the queue and goes to sleep
- messages.add() is executed but no call to display.wakeThread() is issued. Leaving the display in sleep despite the fact that messages are available for processing.
One possible solution might be the following:
void addLast (RunnableLock lock) {
messages.add(lock);
if (messages.peek()==lock) display.wakeThread ();
}
This relies on the assumption that the queue was empty when the lock has been added or another element at the head of the queue has already been consumed since the insertion.
Therefore the wakeThread call might be made without necessity but a unnecessary call is better than no call when one is needed.
To Reproduce
Expected behavior
display should receive a wakeThread whenever it has gone to sleep, because of an empty message queue.
Screenshots
none
Environment:
- Select the platform(s) on which the behavior is seen:
-
- All OS
-
- Windows
-
- Linux
-
- macOS
-
Additional OS info (e.g. OS version, Linux Desktop, etc)
-
JRE/JDK version
Observed on JDK 21
Version since
I think the probem was introduced in SWT 4.30
Workaround (or) Additional context
none