Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Win32: Fix object::cache::threadmania test on x64 #2409

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

Merged
merged 2 commits into from
Jun 8, 2014

Conversation

phkelley
Copy link
Member

@phkelley phkelley commented Jun 7, 2014

The object::cache::threadmania test consistently crashes on Win32 x64. This is because the pthread API against which the test is written specifies a thread's return value as being pointer-sized. On Win32, the return value of a thread is 32 bits on all platforms, and so a pointer doesn't fit platforms with larger pointer sizes. When the return value is sized-up back to a pointer and dereferenced, the test case crashes.

This change fixes the problem by turning git_thread into a structure on Win32 with room for the thread handle, entry procedure pointer, and a void * parameter / return value member. To accomodate the programming model, the git_thread_join macro has been modified to require the address of a git_thread instead of passing it by value. This avoids passing a structure by value. The other git_thread function macros in use already accepted a git_thread * and did not require modification.

A randomly generated magic number incorporated into win32\pthread.c is used to check for clean thread exit. In the case of unclean exit, the value member of the git_win32_thread structure still contains the opaque value passed into the thread entry procedure, and should not be returned to the caller of git_thread_join as a proper return value. Furthermore, we should ensure that all threads started by the library terminate gracefully, so the implementation also raises an assert in the case of unclean thread termination.

While here I also fixed up a couple of warnings in global.c that MinGW complains about, and simplified the initialization logic for the Vista+ reader-writer lock function pointers.

@@ -78,7 +78,7 @@ static void git__shutdown(void)
static DWORD _tls_index;
static volatile LONG _mutex = 0;

static int synchronized_threads_init()
static int synchronized_threads_init(void)
Copy link
Member Author

Choose a reason for hiding this comment

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

The GCC in MinGW was complaining about this.

@phkelley
Copy link
Member Author

phkelley commented Jun 7, 2014

Thanks for the feedback. I've pushed some reaction changes for you to take a look at when you get a chance. If approved, I can squash this down.

vmg pushed a commit that referenced this pull request Jun 8, 2014
Win32: Fix object::cache::threadmania test on x64
@vmg vmg merged commit 9560203 into libgit2:development Jun 8, 2014
@vmg
Copy link
Member

vmg commented Jun 8, 2014

A++ would merge Windows fixes again

phatblat pushed a commit to phatblat/libgit2 that referenced this pull request Sep 13, 2014
Win32: Fix object::cache::threadmania test on x64
@phkelley phkelley deleted the win32_thread_fixes branch April 25, 2020 22:33
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