Skip to content

Fix #574 (deadlocks in player.c) - #710

Merged
flyingmutant merged 4 commits into
cmus:masterfrom
mahkoh:fix-deadlock
Dec 2, 2017
Merged

flyingmutant merged 4 commits into
cmus:masterfrom
mahkoh:fix-deadlock

Conversation

@mahkoh

@mahkoh mahkoh commented Jun 24, 2017 •

Copy link
Copy Markdown
Member

Tl;dr: The UI thread no longer waits for the player to perform its requests (player_next, etc.) Instead it simply schedules the commands and returns immediately. This allows the UI thread to reply to cmus_get_next requests that occur while the player holds its locks.

Fixes #574.

@mahkoh
mahkoh requested a review from flyingmutant June 24, 2017 00:42
@mahkoh
mahkoh force-pushed the fix-deadlock branch 4 times, most recently from a71dba6 to 0fa5abb Compare June 24, 2017 11:44
mahkoh added 4 commits June 24, 2017 13:52
These functions allow void functions that would usually block the UI
thread to run in a separate thread. They are accompanied by a series of
macros that easily turn any given void function (with 0 to 3 arguments)
into a function that runs in the aforementioned thread.

For example, consider the following function:

```c
void f(const char *name)
{
    printf("Hello %s!\n", name);
    sleep(10);
}
```

Applying the macros produces:

```c
DELEGATE_1(f, const char *, name)
{
    printf("Hello %s!\n", name);
    sleep(10);
}
```

A call to `f` now returns immediately and the function prints and sleeps
in the dedicated thread.

NOTE: There is only one such thread and the call above will block all
other delegated functions for 10 seconds.
In preparation of turning this function into a delegated one.
Instead call it from within ui_curses like the rest of the mpris
functions.
This prevents the problem where the UI thread tried to acquire the
player lock while the player thread tried to talk to the UI thread. This
caused deadlocks.

NOTE: Deadlocks can still occur when the player exits because
player_exit cannot be delegated.
@mahkoh

mahkoh commented Jun 24, 2017

Copy link
Copy Markdown
Member Author

I'm still figuring out some places where the code assumed that the functions were synchronous.

@flyingmutant

Copy link
Copy Markdown
Member

Thanks a lot for the PR! The review can take some time though, sorry about that.

@mahkoh

mahkoh commented Jun 28, 2017

Copy link
Copy Markdown
Member Author

Don't worry about it. It's not done yet though so don't bother with the review yet.

@tagniam

tagniam commented Jul 7, 2017

Copy link
Copy Markdown
Contributor

@mahkoh Will the delegate functions in 0654847 allow any command to be run asynchronously? They look like they would help me in addressing the issues of #675.

@Wang-Yue

Wang-Yue commented Dec 1, 2017 •

Copy link
Copy Markdown
Contributor

This has been blocking the release for so long.

@flyingmutant
flyingmutant merged commit ee368a1 into cmus:master Dec 2, 2017
@flyingmutant

Copy link
Copy Markdown
Member

True.

@Wang-Yue

Wang-Yue commented Dec 3, 2017

Copy link
Copy Markdown
Contributor

Please revert this commit. This breaks CoreAudio's mixer initializer.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants