Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vcpkg] Use named mutex to serialize dll copies #11363

Merged
merged 1 commit into from
Oct 28, 2020

Conversation

thomasgt
Copy link
Contributor

Fixes #11089

I'm not sure if this is the best idea, but it does seem to prevent multiple parallel build workers from clobbering a common CMAKE_RUNTIME_OUTPUT_DIRECTORY when copying runtime deps via applocal.ps1.

@msftclas
Copy link

msftclas commented May 14, 2020

CLA assistant check
All CLA requirements met.

@JackBoosY
Copy link
Contributor

Hi @thomasgt, please resolve the conflicts.

Thanks.

@thomasgt
Copy link
Contributor Author

Sure, just rebased onto master.

@JackBoosY JackBoosY added needs-feature-review info:reviewed Pull Request changes follow basic guidelines and removed waiting for response labels May 15, 2020
}
finally
{
$mtx.ReleaseMutex() | Out-Null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this needs a null check but I doubt we care...

@PhoebeHui PhoebeHui changed the title Use named mutex to serialize dll copies [vcpkg] Use named mutex to serialize dll copies May 15, 2020
@thomasgt
Copy link
Contributor Author

I didn't look closely enough at the resolve function. It calls itself recursively. I guess System.Threading.Mutex doesn't mind recursive waits from the same thread, but this wasn't really my intention. I think it'd be more clear if I just wrap the outer call to resolve with the mutex.

@thomasgt
Copy link
Contributor Author

On the other hand, I guess if other scripts make use of the resolve function, maybe it's better to keep this serialization logic inside? The only usages I've found are from port specific deploy functions that are called from within resolve itself. Just let me know what you think and I'll update accordingly.

@strega-nil
Copy link
Contributor

@thomasgt It's not documented, afaict, whether System.Threading.Mutex is recursive or not; therefore, would you mind doing a transform on the code where the recursive bit is pulled out into it's own function, and the existing function just takes the mutex and calls this function?

@strega-nil strega-nil added waiting for response and removed needs-feature-review info:reviewed Pull Request changes follow basic guidelines labels May 18, 2020
@thomasgt
Copy link
Contributor Author

thomasgt commented Jun 9, 2020

@strega-nil Done. Let me know if there's anything else I can clean up!

@JackBoosY JackBoosY added category:vcpkg-feature The issue is a new capability of the tool that doesn’t already exist and we haven’t committed and removed requires:author-response labels Jun 9, 2020
finally
{
if ($mtx) {
$mtx.ReleaseMutex() | Out-Null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't ReleaseMutex unless WaitOne succeeded.

@@ -90,6 +90,24 @@ function resolve([string]$targetBinary) {
Write-Verbose "Done Resolving $targetBinary."
}

function copyRuntimeDependencies([string]$targetBinary) {
try {
$mtx = New-Object System.Threading.Mutex($false, "VcpkgAppLocalResolve")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably include the current vcpkg path in here somehow so that totally different vcpkgs don't step on each other.

(Before I knew that we recursively used this when building some ports in vcpkg I was less concerned :) )

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternately: Should we protect deployBinary on a per binary basis rather than the overall resolution step?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Protecting deployBinary might be a better approach, actually. We could scope the Mutex to a combination of deployBinary's $targetBinaryDir and $targetBinaryName arguments? In that case, there would be no need to include the vcpkg path.

@JackBoosY
Copy link
Contributor

Please merge the latest changes into this branch.

@BillyONeal
Copy link
Member

@thomasgt Are you interested in addressing the above CR comments?

@thomasgt
Copy link
Contributor Author

thomasgt commented Sep 5, 2020

@BillyONeal This slipped my mind... Yes, I'd be happy to tidy this up next week. I'll take the approach of serializing deployBinary as I alluded to in my reply a few months back.

@BillyONeal
Copy link
Member

Sounds good, thanks :D

@thomasgt
Copy link
Contributor Author

OK, finally tidied this up. I am scoping the mutex to the target directory, which should let simultaneous builds using vcpkg work as normal, unless they are writing to the same target directory, in which case the DLL copies will be serialized.

@JackBoosY
Copy link
Contributor

ping @BillyONeal for review this PR.

@JackBoosY
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@BillyONeal
Copy link
Member

@JackBoosY Can you mark status:reviewed in the future if you want the "on call" person to take a look? That way others can see too. Thanks!

@BillyONeal BillyONeal merged commit 10771a8 into microsoft:master Oct 28, 2020
@BillyONeal
Copy link
Member

Thanks for your contribution!

Jimmy-Hu added a commit to Jimmy-Hu/vcpkg that referenced this pull request Oct 28, 2020
Serialize deployBinary on target directory (microsoft#11363)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:vcpkg-feature The issue is a new capability of the tool that doesn’t already exist and we haven’t committed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Copying DLLs via applocal.ps1 produces noisy logs during parallel builds
5 participants