Skip to content

Synchronization issue in Synchronizer #3151

@meyertom

Description

@meyertom

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:

  1. messages isEmpty() returns false,
  2. the consuming side empties the queue and goes to sleep
  3. 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:

  1. Select the platform(s) on which the behavior is seen:
    • All OS
    • Windows
    • Linux
    • macOS
  1. Additional OS info (e.g. OS version, Linux Desktop, etc)

  2. JRE/JDK version
    Observed on JDK 21

Version since
I think the probem was introduced in SWT 4.30

Workaround (or) Additional context
none

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions