Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Implement CreateSemaphoreExA/W via CreateSemaphoreA/W#261

Merged
stephentoub merged 1 commit into
dotnet:masterfrom
stephentoub:fix_semaphore
Feb 13, 2015
Merged

Implement CreateSemaphoreExA/W via CreateSemaphoreA/W#261
stephentoub merged 1 commit into
dotnet:masterfrom
stephentoub:fix_semaphore

Conversation

@stephentoub
Copy link
Copy Markdown
Member

Any managed code that touches the ThreadPool is currently crashing when the ThreadPool tries to initialize. This is due to it creating a semaphore via CreateSemaphoreEx in the pal, and those functions not being implemented.

To help make forward progress, this commit just implements those functions simply by delegating to their non-Ex counterparts, ignoring the additional arguments that come with the Ex versions. With this change, ThreadPool.QueueUserWorkItem, Task.Run, etc. are able to successfully schedule work and have it executed.

I've left the "TODO: Implement this!" comments in place, under the assumption that these implementations are shortish-term workarounds.

@janvorli
Copy link
Copy Markdown
Member

Thanks Steve. It looks like the dwFlags are reserved parameter and must be zero and the CreateSemaphoreExW is used only through the following macro:

#define WszCreateSemaphore(_secattr, _count, _maxcount, _name) CreateSemaphoreExW((_secattr), (_count), (_maxcount), (_name), 0, SEMAPHORE_ALL_ACCESS)

So the only value of the dwDesiredAccess is the SEMAPHORE_ALL_ACCESS. That means that your implementation is complete for the current usage. I'd recommend just asserting that the dwDesiredAccess is the SEMAPHORE_ALL_ACCESS.

Any managed code that touches the ThreadPool is currently crashing when the ThreadPool tries to initialize. This is due to it creating a semaphore via CreateSemaphoreExA/W in the pal, and those functions not being implemented.

This commit just implements those functions by delegating to their non-Ex counterparts. With this change, ThreadPool.QueueUserWorkItem, Task.Run, etc. are able to successfully schedule work and have it executed.
@stephentoub
Copy link
Copy Markdown
Member Author

Thanks, Jan. I added the assert and updated the associated comment.

@janvorli
Copy link
Copy Markdown
Member

LGTM

stephentoub added a commit that referenced this pull request Feb 13, 2015
Implement CreateSemaphoreExA/W via CreateSemaphoreA/W
@stephentoub stephentoub merged commit 4db6822 into dotnet:master Feb 13, 2015
@stephentoub stephentoub deleted the fix_semaphore branch February 13, 2015 21:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants