[PATCH] msvcp120: implement _Cnd_* functions (try 2)

Piotr Caban piotr.caban at gmail.com
Mon Nov 9 10:23:22 CST 2015


On 11/09/15 16:38, Daniel Lehman wrote:
> +static int (__cdecl*p__Mtx_init)(_Mtx_t*);
This function has different header.

> +    if (0) /* causes crash in later_Cnd_* calls on Windows */
> +        p__Cnd_destroy(&cm.cnd);
This is not what I meant. I'm attaching a patch (generated on top of 
yours with the test I had in mind). It only shows the problem, the test 
needs more work.

 > +    for(i = 0; i < NUM_THREADS; i++)
 > +        p__Thrd_create(&threads[i], cnd_bcast_thread, (void*)&cm);
...
> +    p__Mtx_lock(&mtx);
> +    cm.go = 1;
> +    p__Mtx_unlock(&mtx);
Please add some kind of synchronization to make sure the thread is 
waiting on condition variable before setting cm.go to 1.

> +    cm.go = 0;
> +    p__Thrd_create(&threads[0], cnd_signal_thread, (void*)&cm);
> +    p__Mtx_lock(&mtx);
> +    while(!cm.go) {
> +        r = p__Cnd_wait(&cnd, &mtx);
> +        ok(!r, "failed to wait\n");
> +    }
Here's a similar synchronization problem. In most cases p__Cnd_wait will 
not be called.

> +    diff = p__Xtime_diff_to_millis2(&after, &before);
> +    ok(r == 2, "should have timed out\n");
> +    ok(diff > 2000 - TIMEDELTA, "got %d\n", diff);
This test failed once on my computer (in ~10 runs, diff == 1800).

Thanks,
Piotr
-------------- next part --------------
diff --git a/dlls/msvcp120/tests/msvcp120.c b/dlls/msvcp120/tests/msvcp120.c
index 8991420..fddb5b0 100644
--- a/dlls/msvcp120/tests/msvcp120.c
+++ b/dlls/msvcp120/tests/msvcp120.c
@@ -1314,7 +1314,9 @@ static int __cdecl cnd_bcast_thread(void *arg)
 
     p__Mtx_lock(&cm->mtx);
     while(!cm->go) {
+        trace("enter wait\n");
         r = p__Cnd_wait(&cm->cnd, &cm->mtx);
+        trace("done waiting\n");
         ok(!r, "failed to wait\n");
     }
     p__Mtx_unlock(&cm->mtx);
@@ -1367,8 +1369,15 @@ static void test_cnd(void)
     for(i = 0; i < NUM_THREADS; i++)
         p__Thrd_create(&threads[i], cnd_bcast_thread, (void*)&cm);
 
-    if (0) /* causes crash in later _Cnd_* calls on Windows */
-        p__Cnd_destroy(&cm.cnd);
+    p__Mtx_lock(&mtx);
+    cm.go = 1;
+    p__Mtx_unlock(&mtx);
+    Sleep(1000);
+    p__Cnd_destroy(&cm.cnd);
+
+    for(i = 0; i < NUM_THREADS; i++)
+        p__Thrd_join(threads[i], NULL);
+    return;
 
     p__Mtx_lock(&mtx);
     cm.go = 1;


More information about the wine-devel mailing list