-
Notifications
You must be signed in to change notification settings - Fork 15k
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
Implemented thread handling for WaitForMultipleObjects. #1964
Conversation
Test FAILed. |
Test FAILed. |
Test FAILed. |
Test FAILed. |
@freerdp-bot test |
Test PASSed. |
Test FAILed. |
+1, code looks good besides the failing test |
Test PASSed. |
@MartinHaimberger Last commit fixes failing tests. |
Test PASSed. |
|
||
fprintf(stderr, "---------------- End Dumping thread handles -------------\n"); | ||
} | ||
#endif | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really do like this idea!
@bmiklautz @MartinHaimberger Added support for bWaitAll and fixed bugs found during testing, looks more solid now. Could you please confirm? |
Test FAILed. |
Test FAILed. |
@freerdp-bot test |
Test PASSed. |
@bmiklautz @MartinHaimberger @awakecoding @mfleisz @nfedera Did some more testing, working quite well now. Could you check if it works for you as well? |
Test PASSed. |
|
||
#endif | ||
} | ||
|
||
/** | ||
* TODO: implement thread suspend/resume using pthreads | ||
* http://stackoverflow.com/questions/3140867/suspend-pthreads-without-using-condition | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've read the article and I really don't know who would want a pthread_suspend() function. When a thread gets suspended it should always be a volontary action (from the thread). Otherwise you can get suspended with some mutex hold and lead to a deadlock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hardening if I'm not mistaken windows can create a suspended thread so I guess that why one want that in winpr.
With the recent changes around monolithic, can't a Thread have an Event instead of dupllicating the Event code in Thread ? |
except my remark LGTM, +1 |
@hardening could probably be done. Just didn't want the dependency on event in thread to avoid the effort (recursive calls, ...) for testing. |
Test PASSed. |
3a30f2e
to
e73e64d
Compare
Test FAILed. |
Test FAILed. |
@freerdp-bot test |
Fixed setting of started flag for threads. pthred_exit now used correct return value argument. Return value now also set when terminating thread.
Implemented bWaitAll for WaitForMultipleObjects. pthread_join now only called on first wait event, later ones skip this to avoid undefined behavior.
3afa77b
to
5bf25fd
Compare
Test FAILed. |
@freerdp-bot test |
Test FAILed. |
@freerdp-bot test |
Test PASSed. |
|
||
thread->started = FALSE; | ||
if (!thread->joined) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a race condition on this variable if 2 threads call WaitForSingleObject() concurrently.
pthread_join() is atomically correct with this, so we should call it inconditionaly, and we can remove this struct member too (joined).
@akallabeth sorry to comment so late. |
@akallabeth: Looks good despite the two comments from @hardening. If this is fixed I'll merge since this has been open for ages and nobody seems to have any objections. |
So, fixed the races. The flag is still there (preventing multiple waits to call pthread_join, which is undefined) but it is locked by a mutex now. |
Test PASSed. |
pthread_join() is a real pain, it's functional only for trivial, limited, cases, which is of course the one you never hit in real programs. I don't know why they gave such a stupid definition for pthread_join()... Anyway I guess that in We could use a pthread_condition stored in the thread to accomplish the same operation and allowing multiple thread to wait for completion. The pthread_condition would also allow to do a wait with timeout. It's not a brilliant idea from me it's just that many toolkit are doing it this way (at least Qt, and others) |
{ | ||
WLog_ERR(TAG, "pthread_join failure: [%d] %s", | ||
status, strerror(status)); | ||
return WAIT_FAILED; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this exit path we're still holding the thread->mutex lock
Test PASSed. |
Implemented thread handling for WaitForMultipleObjects.
Implemented thread specific functions:
** Add DumpThreadHandles wherever you want to know the state of thread handles