On occasion the second thread, started by Continue(), will run far enough that it effectively steals the Switch() call out from under the first thread. Ensure that this doesn't happen by causing the second thread to wait for the first thread to finish before running any code.
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/urlmon/tests/protocol.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/dlls/urlmon/tests/protocol.c b/dlls/urlmon/tests/protocol.c index d88aa07..1d9a803 100644 --- a/dlls/urlmon/tests/protocol.c +++ b/dlls/urlmon/tests/protocol.c @@ -156,6 +156,7 @@ static DWORD prot_read, filter_state, http_post_test, thread_id; static BOOL security_problem, test_async_req, impl_protex; static BOOL async_read_pending, mimefilter_test, direct_read, wait_for_switch, emulate_prot, short_read, test_abort; static BOOL empty_file, no_mime, bind_from_cache, file_with_hash; +static HANDLE last_thread, thread;
enum { STATE_CONNECTING, @@ -1592,6 +1593,10 @@ static DWORD WINAPI thread_proc(PVOID arg) BOOL redirect_only = redirect_on_continue; HRESULT hres;
+ /* make sure that the last thread terminates before we start this one */ + if (last_thread) + ok(WaitForSingleObject(last_thread, 90000) == WAIT_OBJECT_0, "wait timed out\n"); + memset(&protocoldata, -1, sizeof(protocoldata));
prot_state = 0; @@ -1719,7 +1724,6 @@ static void protocol_start(IInternetProtocolSink *pOIProtSink, IInternetBindInfo LPWSTR additional_headers = NULL; BYTE sec_id[100]; DWORD fetched = 0, size = 100; - DWORD tid;
SET_EXPECT(GetBindString_USER_AGENT); hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_USER_AGENT, @@ -1777,7 +1781,8 @@ static void protocol_start(IInternetProtocolSink *pOIProtSink, IInternetBindInfo
IServiceProvider_Release(service_provider);
- CreateThread(NULL, 0, thread_proc, NULL, 0, &tid); + last_thread = thread; + thread = CreateThread(NULL, 0, thread_proc, NULL, 0, NULL); return; }
Hi Zebediah,
On 09.01.2018 03:23, Zebediah Figura wrote:
- /* make sure that the last thread terminates before we start this one */
- if (last_thread)
ok(WaitForSingleObject(last_thread, 90000) == WAIT_OBJECT_0, "wait timed out\n");
We already have event_complete for similar purpose. Would setting the event in thread_proc before returning in redirect_only branch and waiting for it in ProtocolEmul_Continue before ReportResult(INET_E_REDIRECT_FAILED) call solve the problem?
Thanks,
Jacek
On 01/10/2018 02:50 PM, Jacek Caban wrote:
Hi Zebediah,
On 09.01.2018 03:23, Zebediah Figura wrote:
- /* make sure that the last thread terminates before we start this one */
- if (last_thread)
ok(WaitForSingleObject(last_thread, 90000) == WAIT_OBJECT_0, "wait timed out\n");
We already have event_complete for similar purpose. Would setting the event in thread_proc before returning in redirect_only branch and waiting for it in ProtocolEmul_Continue before ReportResult(INET_E_REDIRECT_FAILED) call solve the problem?
Thanks,
Jacek
Hi, thanks for the attention.
Unfortunately that doesn't work because calling Switch() [from the thread] waits for Continue() [on the main thread] to complete, i.e. it waits for event_complete2.
On 10.01.2018 22:21, Zebediah Figura wrote:
On 01/10/2018 02:50 PM, Jacek Caban wrote:
Hi Zebediah,
On 09.01.2018 03:23, Zebediah Figura wrote:
- /* make sure that the last thread terminates before we start this one */
- if (last_thread)
ok(WaitForSingleObject(last_thread, 90000) == WAIT_OBJECT_0, "wait timed out\n");
We already have event_complete for similar purpose. Would setting the event in thread_proc before returning in redirect_only branch and waiting for it in ProtocolEmul_Continue before ReportResult(INET_E_REDIRECT_FAILED) call solve the problem?
Thanks,
Jacek
Hi, thanks for the attention.
Thanks for fixing it.
Unfortunately that doesn't work because calling Switch() [from the thread] waits for Continue() [on the main thread] to complete, i.e. it waits for event_complete2.
It seems to me that we could simply set event_complete2 before waiting for event_complete.
Jacek