The attached patch lets you run Wine's conformance tests in parallel.

On my relatively fast dual core machine (e7200):
"make -k     test" takes 3 minutes 55 seconds
"make -k -j2 test" takes 2 minutes 15 seconds
"make -k -j4 test" takes 1 minute 45 seconds
"make -k -j10 test" takes 1 minute 27 seconds

About the same number of tests fail regardless of -j value.

How it works:
this patch adds a new function, winetest_exclusive(),
that waits until it can acquire an exclusive lock.
It should be called near the top of the START_TEST body
for any test that needs exclusive access to the
system.  (In tests that exec themselves, the call has to
be placed carefully to avoid having the child call it.)
I did this for all tests that call CreateWindow, and
a few more that seemed like they might need it.

The list of tests marked exclusive is somewhat rough;
probably a few tests should be added or removed,
but it's pretty good for a first cut.

I've been wanting to do this for ages.  Turned out to be easier than I'd feared.
diff --git a/dlls/comctl32/tests/comboex.c b/dlls/comctl32/tests/comboex.c
index eca7ca4..7fe0874 100644
--- a/dlls/comctl32/tests/comboex.c
+++ b/dlls/comctl32/tests/comboex.c
@@ -339,6 +339,8 @@ static void cleanup(void)
 
 START_TEST(comboex)
 {
+    winetest_exclusive();
+
     if (!init())
         return;
 
diff --git a/dlls/comctl32/tests/datetime.c b/dlls/comctl32/tests/datetime.c
index b194cc1..5bff228 100644
--- a/dlls/comctl32/tests/datetime.c
+++ b/dlls/comctl32/tests/datetime.c
@@ -579,6 +579,8 @@ START_TEST(datetime)
     BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
     INITCOMMONCONTROLSEX iccex;
 
+    winetest_exclusive();
+
     hComctl32 = GetModuleHandleA("comctl32.dll");
     pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
     if (!pInitCommonControlsEx)
diff --git a/dlls/comctl32/tests/header.c b/dlls/comctl32/tests/header.c
index a3778cf..c62dca2 100644
--- a/dlls/comctl32/tests/header.c
+++ b/dlls/comctl32/tests/header.c
@@ -1524,6 +1524,8 @@ START_TEST(header)
 {
     HWND parent_hwnd;
 
+    winetest_exclusive();
+
     if (!init())
         return;
 
diff --git a/dlls/comctl32/tests/imagelist.c b/dlls/comctl32/tests/imagelist.c
index 0d1770b..76600ec 100644
--- a/dlls/comctl32/tests/imagelist.c
+++ b/dlls/comctl32/tests/imagelist.c
@@ -976,6 +976,9 @@ static void test_imagelist_storage(void)
 START_TEST(imagelist)
 {
     HMODULE hComCtl32 = GetModuleHandle("comctl32.dll");
+
+    winetest_exclusive();
+
     pImageList_DrawIndirect = (void*)GetProcAddress(hComCtl32, "ImageList_DrawIndirect");
     pImageList_SetImageCount = (void*)GetProcAddress(hComCtl32, "ImageList_SetImageCount");
 
diff --git a/dlls/comctl32/tests/listview.c b/dlls/comctl32/tests/listview.c
index 4f8b32d..8069835 100644
--- a/dlls/comctl32/tests/listview.c
+++ b/dlls/comctl32/tests/listview.c
@@ -1216,6 +1216,8 @@ START_TEST(listview)
     HMODULE hComctl32;
     BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
 
+    winetest_exclusive();
+
     hComctl32 = GetModuleHandleA("comctl32.dll");
     pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
     if (pInitCommonControlsEx)
diff --git a/dlls/comctl32/tests/monthcal.c b/dlls/comctl32/tests/monthcal.c
index cd9592d..bd167f2 100644
--- a/dlls/comctl32/tests/monthcal.c
+++ b/dlls/comctl32/tests/monthcal.c
@@ -1114,6 +1114,8 @@ START_TEST(monthcal)
     INITCOMMONCONTROLSEX iccex;
     HWND hwnd, parent_wnd;
 
+    winetest_exclusive();
+
     hComctl32 = GetModuleHandleA("comctl32.dll");
     pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
     if (!pInitCommonControlsEx)
diff --git a/dlls/comctl32/tests/msg.c b/dlls/comctl32/tests/msg.c
index 2129f22..b1fe203 100644
--- a/dlls/comctl32/tests/msg.c
+++ b/dlls/comctl32/tests/msg.c
@@ -248,4 +248,5 @@ void init_msg_sequences(struct msg_sequence **seq, int n)
 
 START_TEST(msg)
 {
+    winetest_exclusive();
 }
diff --git a/dlls/comctl32/tests/progress.c b/dlls/comctl32/tests/progress.c
index 10bbbef..bf9a455 100644
--- a/dlls/comctl32/tests/progress.c
+++ b/dlls/comctl32/tests/progress.c
@@ -222,6 +222,8 @@ static void test_redraw(void)
 
 START_TEST(progress)
 {
+    winetest_exclusive();
+
     init();
     
     test_redraw();
diff --git a/dlls/comctl32/tests/propsheet.c b/dlls/comctl32/tests/propsheet.c
index 45c8d97..1f7b612 100644
--- a/dlls/comctl32/tests/propsheet.c
+++ b/dlls/comctl32/tests/propsheet.c
@@ -201,6 +201,8 @@ static void test_disableowner(void)
 
 START_TEST(propsheet)
 {
+    winetest_exclusive();
+
     test_title();
     test_nopage();
     test_disableowner();
diff --git a/dlls/comctl32/tests/rebar.c b/dlls/comctl32/tests/rebar.c
index e5bea38..fdb18d3 100644
--- a/dlls/comctl32/tests/rebar.c
+++ b/dlls/comctl32/tests/rebar.c
@@ -835,6 +835,8 @@ START_TEST(rebar)
     MSG msg;
     RECT rc;
 
+    winetest_exclusive();
+
     /* LoadLibrary is needed. This file has no references to functions in comctl32 */
     hComctl32 = LoadLibraryA("comctl32.dll");
     pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
diff --git a/dlls/comctl32/tests/status.c b/dlls/comctl32/tests/status.c
index 4e643c1..e910c92 100644
--- a/dlls/comctl32/tests/status.c
+++ b/dlls/comctl32/tests/status.c
@@ -190,6 +190,8 @@ START_TEST(status)
 {
     hinst = GetModuleHandleA(NULL);
 
+    winetest_exclusive();
+
     InitCommonControls();
 
     test_status_control();
diff --git a/dlls/comctl32/tests/tab.c b/dlls/comctl32/tests/tab.c
index 9489376..cffcc4d 100644
--- a/dlls/comctl32/tests/tab.c
+++ b/dlls/comctl32/tests/tab.c
@@ -961,6 +961,8 @@ START_TEST(tab)
     HWND parent_wnd;
     LOGFONTA logfont;
 
+    winetest_exclusive();
+
     lstrcpyA(logfont.lfFaceName, "Arial");
     memset(&logfont, 0, sizeof(logfont));
     logfont.lfHeight = -12;
diff --git a/dlls/comctl32/tests/toolbar.c b/dlls/comctl32/tests/toolbar.c
index 2693025..1e0d63f 100644
--- a/dlls/comctl32/tests/toolbar.c
+++ b/dlls/comctl32/tests/toolbar.c
@@ -1128,6 +1128,8 @@ START_TEST(toolbar)
     MSG msg;
     RECT rc;
   
+    winetest_exclusive();
+
     InitCommonControls();
   
     wc.style = CS_HREDRAW | CS_VREDRAW;
diff --git a/dlls/comctl32/tests/tooltips.c b/dlls/comctl32/tests/tooltips.c
index e9bce63..53f171f 100644
--- a/dlls/comctl32/tests/tooltips.c
+++ b/dlls/comctl32/tests/tooltips.c
@@ -234,6 +234,8 @@ static void test_customdraw(void) {
 
 START_TEST(tooltips)
 {
+    winetest_exclusive();
+
     InitCommonControls();
 
     test_create_tooltip();
diff --git a/dlls/comctl32/tests/treeview.c b/dlls/comctl32/tests/treeview.c
index c1ba7f3..bc2ecbc 100644
--- a/dlls/comctl32/tests/treeview.c
+++ b/dlls/comctl32/tests/treeview.c
@@ -654,6 +654,8 @@ START_TEST(treeview)
     WNDCLASSA wc;
     MSG msg;
   
+    winetest_exclusive();
+
     hComctl32 = GetModuleHandleA("comctl32.dll");
     pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
     if (pInitCommonControlsEx)
diff --git a/dlls/comctl32/tests/updown.c b/dlls/comctl32/tests/updown.c
index 6f8e395..5867250 100644
--- a/dlls/comctl32/tests/updown.c
+++ b/dlls/comctl32/tests/updown.c
@@ -585,6 +585,8 @@ static void test_create_updown_control(void)
 
 START_TEST(updown)
 {
+    winetest_exclusive();
+
     InitCommonControls();
     init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
 
diff --git a/dlls/crypt32/tests/msg.c b/dlls/crypt32/tests/msg.c
index e88d382..8b9c562 100644
--- a/dlls/crypt32/tests/msg.c
+++ b/dlls/crypt32/tests/msg.c
@@ -2646,7 +2646,9 @@ static void test_verify_message_signature(void)
 
 START_TEST(msg)
 {
-     init_function_pointers();
+    winetest_exclusive();
+
+    init_function_pointers();
 
     /* Basic parameter checking tests */
     test_msg_open_to_encode();
diff --git a/dlls/d3d8/tests/device.c b/dlls/d3d8/tests/device.c
index d40f196..3273292 100644
--- a/dlls/d3d8/tests/device.c
+++ b/dlls/d3d8/tests/device.c
@@ -1329,6 +1329,8 @@ START_TEST(device)
         return;
     }
 
+    winetest_exclusive();
+
     pDirect3DCreate8 = (void *)GetProcAddress( d3d8_handle, "Direct3DCreate8" );
     ok(pDirect3DCreate8 != NULL, "Failed to get address of Direct3DCreate8\n");
     if (pDirect3DCreate8)
diff --git a/dlls/d3d8/tests/surface.c b/dlls/d3d8/tests/surface.c
index 86fb884..71007be 100644
--- a/dlls/d3d8/tests/surface.c
+++ b/dlls/d3d8/tests/surface.c
@@ -322,6 +322,8 @@ START_TEST(surface)
     HMODULE d3d8_handle;
     IDirect3DDevice8 *device_ptr;
 
+    winetest_exclusive();
+
     d3d8_handle = LoadLibraryA("d3d8.dll");
     if (!d3d8_handle)
     {
diff --git a/dlls/d3d8/tests/texture.c b/dlls/d3d8/tests/texture.c
index a002763..7ab1ef7 100644
--- a/dlls/d3d8/tests/texture.c
+++ b/dlls/d3d8/tests/texture.c
@@ -133,6 +133,8 @@ START_TEST(texture)
     HMODULE d3d8_handle;
     IDirect3DDevice8 *device_ptr;
 
+    winetest_exclusive();
+
     d3d8_handle = LoadLibraryA("d3d8.dll");
     if (!d3d8_handle)
     {
diff --git a/dlls/d3d8/tests/visual.c b/dlls/d3d8/tests/visual.c
index 33d6176..6c48b33 100644
--- a/dlls/d3d8/tests/visual.c
+++ b/dlls/d3d8/tests/visual.c
@@ -1272,6 +1272,8 @@ START_TEST(visual)
     DWORD color;
     D3DCAPS8 caps;
 
+    winetest_exclusive();
+
     d3d8_handle = LoadLibraryA("d3d8.dll");
     if (!d3d8_handle)
     {
diff --git a/dlls/d3d8/tests/volume.c b/dlls/d3d8/tests/volume.c
index aee0c3a..cd0dd57 100644
--- a/dlls/d3d8/tests/volume.c
+++ b/dlls/d3d8/tests/volume.c
@@ -127,6 +127,8 @@ START_TEST(volume)
     IDirect3DDevice8 *device_ptr;
     D3DCAPS8 caps;
 
+    winetest_exclusive();
+
     d3d8_handle = LoadLibraryA("d3d8.dll");
     if (!d3d8_handle)
     {
diff --git a/dlls/d3d9/tests/d3d9ex.c b/dlls/d3d9/tests/d3d9ex.c
index 3917a57..aebbf63 100644
--- a/dlls/d3d9/tests/d3d9ex.c
+++ b/dlls/d3d9/tests/d3d9ex.c
@@ -182,6 +182,8 @@ out:
 
 START_TEST(d3d9ex)
 {
+    winetest_exclusive();
+
     d3d9_handle = LoadLibraryA("d3d9.dll");
     if (!d3d9_handle)
     {
diff --git a/dlls/d3d9/tests/device.c b/dlls/d3d9/tests/device.c
index 3a56298..ff78cd4 100644
--- a/dlls/d3d9/tests/device.c
+++ b/dlls/d3d9/tests/device.c
@@ -2060,6 +2060,8 @@ START_TEST(device)
         return;
     }
 
+    winetest_exclusive();
+
     pDirect3DCreate9 = (void *)GetProcAddress( d3d9_handle, "Direct3DCreate9" );
     ok(pDirect3DCreate9 != NULL, "Failed to get address of Direct3DCreate9\n");
     if (pDirect3DCreate9)
diff --git a/dlls/d3d9/tests/query.c b/dlls/d3d9/tests/query.c
index 6e8b4c9..3ba7e31 100644
--- a/dlls/d3d9/tests/query.c
+++ b/dlls/d3d9/tests/query.c
@@ -240,6 +240,8 @@ START_TEST(query)
         return;
     }
 
+    winetest_exclusive();
+
     pDirect3DCreate9 = (void *)GetProcAddress( d3d9_handle, "Direct3DCreate9" );
     ok(pDirect3DCreate9 != NULL, "Failed to get address of Direct3DCreate9\n");
     if (pDirect3DCreate9)
diff --git a/dlls/d3d9/tests/shader.c b/dlls/d3d9/tests/shader.c
index 07318e3..d333bc6 100644
--- a/dlls/d3d9/tests/shader.c
+++ b/dlls/d3d9/tests/shader.c
@@ -205,6 +205,8 @@ START_TEST(shader)
     D3DCAPS9 caps;
     IDirect3DDevice9 *device_ptr;
 
+    winetest_exclusive();
+
     d3d9_handle = LoadLibraryA("d3d9.dll");
     if (!d3d9_handle)
     {
diff --git a/dlls/d3d9/tests/stateblock.c b/dlls/d3d9/tests/stateblock.c
index ee5061f..2b98b53 100644
--- a/dlls/d3d9/tests/stateblock.c
+++ b/dlls/d3d9/tests/stateblock.c
@@ -1461,6 +1461,8 @@ START_TEST(stateblock)
     D3DPRESENT_PARAMETERS device_pparams;
     HRESULT hret;
 
+    winetest_exclusive();
+
     d3d9_handle = LoadLibraryA("d3d9.dll");
     if (!d3d9_handle)
     {
diff --git a/dlls/d3d9/tests/surface.c b/dlls/d3d9/tests/surface.c
index 69016f5..3a889e0 100644
--- a/dlls/d3d9/tests/surface.c
+++ b/dlls/d3d9/tests/surface.c
@@ -380,6 +380,8 @@ START_TEST(surface)
     HMODULE d3d9_handle;
     IDirect3DDevice9 *device_ptr;
 
+    winetest_exclusive();
+
     d3d9_handle = LoadLibraryA("d3d9.dll");
     if (!d3d9_handle)
     {
diff --git a/dlls/d3d9/tests/texture.c b/dlls/d3d9/tests/texture.c
index bbc98a7..8b64eaf 100644
--- a/dlls/d3d9/tests/texture.c
+++ b/dlls/d3d9/tests/texture.c
@@ -242,6 +242,8 @@ START_TEST(texture)
     HMODULE d3d9_handle;
     IDirect3DDevice9 *device_ptr;
 
+    winetest_exclusive();
+
     d3d9_handle = LoadLibraryA("d3d9.dll");
     if (!d3d9_handle)
     {
diff --git a/dlls/d3d9/tests/vertexdeclaration.c b/dlls/d3d9/tests/vertexdeclaration.c
index 292087f..d16cf1d 100644
--- a/dlls/d3d9/tests/vertexdeclaration.c
+++ b/dlls/d3d9/tests/vertexdeclaration.c
@@ -795,6 +795,8 @@ START_TEST(vertexdeclaration)
     IDirect3DDevice9 *device_ptr = 0;
     IDirect3DVertexDeclaration9 *decl_ptr = 0;
 
+    winetest_exclusive();
+
     d3d9_handle = LoadLibraryA("d3d9.dll");
     if (!d3d9_handle)
     {
diff --git a/dlls/d3d9/tests/visual.c b/dlls/d3d9/tests/visual.c
index 1522523..8405bcf 100644
--- a/dlls/d3d9/tests/visual.c
+++ b/dlls/d3d9/tests/visual.c
@@ -9218,6 +9218,8 @@ START_TEST(visual)
     HRESULT hr;
     DWORD color;
 
+    winetest_exclusive();
+
     d3d9_handle = LoadLibraryA("d3d9.dll");
     if (!d3d9_handle)
     {
diff --git a/dlls/d3d9/tests/volume.c b/dlls/d3d9/tests/volume.c
index 31066a6..120295c 100644
--- a/dlls/d3d9/tests/volume.c
+++ b/dlls/d3d9/tests/volume.c
@@ -124,6 +124,8 @@ START_TEST(volume)
     IDirect3DDevice9 *device_ptr;
     D3DCAPS9 caps;
 
+    winetest_exclusive();
+
     memset(&caps, 0, sizeof(caps));
     d3d9_handle = LoadLibraryA("d3d9.dll");
     if (!d3d9_handle)
diff --git a/dlls/ddraw/tests/ddrawmodes.c b/dlls/ddraw/tests/ddrawmodes.c
index 95e8657..a4991ec 100644
--- a/dlls/ddraw/tests/ddrawmodes.c
+++ b/dlls/ddraw/tests/ddrawmodes.c
@@ -382,6 +382,8 @@ static void testcooperativelevels_exclusive(void)
 
 START_TEST(ddrawmodes)
 {
+    winetest_exclusive();
+
     createwindow();
     if (!createdirectdraw())
         return;
diff --git a/dlls/ddraw/tests/dsurface.c b/dlls/ddraw/tests/dsurface.c
index 7dba28b..ca9b112 100644
--- a/dlls/ddraw/tests/dsurface.c
+++ b/dlls/ddraw/tests/dsurface.c
@@ -2611,6 +2611,8 @@ static void StructSizeTest(void)
 
 START_TEST(dsurface)
 {
+    winetest_exclusive();
+
     if (!CreateDirectDraw())
         return;
     MipMapCreationTest();
diff --git a/dlls/ddraw/tests/visual.c b/dlls/ddraw/tests/visual.c
index ede24eb..8538a0e 100644
--- a/dlls/ddraw/tests/visual.c
+++ b/dlls/ddraw/tests/visual.c
@@ -2607,6 +2607,9 @@ START_TEST(visual)
 {
     HRESULT hr;
     DWORD color;
+
+    winetest_exclusive();
+
     if(!createObjects())
     {
         skip("Cannot initialize DirectDraw and Direct3D, skipping\n");
diff --git a/dlls/dinput/tests/device.c b/dlls/dinput/tests/device.c
index e59d8c3..7452b8e 100644
--- a/dlls/dinput/tests/device.c
+++ b/dlls/dinput/tests/device.c
@@ -186,6 +186,8 @@ static void device_tests(void)
 
 START_TEST(device)
 {
+    winetest_exclusive();
+
     CoInitialize(NULL);
 
     device_tests();
diff --git a/dlls/dinput/tests/keyboard.c b/dlls/dinput/tests/keyboard.c
index d427e65..ace5576 100644
--- a/dlls/dinput/tests/keyboard.c
+++ b/dlls/dinput/tests/keyboard.c
@@ -193,6 +193,8 @@ static void keyboard_tests(DWORD version)
 
 START_TEST(keyboard)
 {
+    winetest_exclusive();
+
     CoInitialize(NULL);
 
     trace("DLL Version: %s\n", get_file_version("dinput.dll"));
diff --git a/dlls/dinput/tests/mouse.c b/dlls/dinput/tests/mouse.c
index 42e5982..978f5ce 100644
--- a/dlls/dinput/tests/mouse.c
+++ b/dlls/dinput/tests/mouse.c
@@ -143,6 +143,8 @@ static void mouse_tests(void)
 
 START_TEST(mouse)
 {
+    winetest_exclusive();
+
     CoInitialize(NULL);
 
     trace("DLL Version: %s\n", get_file_version("dinput.dll"));
diff --git a/dlls/gdi32/tests/clipping.c b/dlls/gdi32/tests/clipping.c
index 0ae3eb6..16290a1 100644
--- a/dlls/gdi32/tests/clipping.c
+++ b/dlls/gdi32/tests/clipping.c
@@ -258,6 +258,8 @@ if (0) /* crashes under Win9x */
 
 START_TEST(clipping)
 {
+    winetest_exclusive();
+
     test_GetRandomRgn();
     test_ExtCreateRegion();
 }
diff --git a/dlls/gdi32/tests/dc.c b/dlls/gdi32/tests/dc.c
index 9e0048e..4b2fe1c 100644
--- a/dlls/gdi32/tests/dc.c
+++ b/dlls/gdi32/tests/dc.c
@@ -255,6 +255,8 @@ static void test_CreateCompatibleDC(void)
 
 START_TEST(dc)
 {
+    winetest_exclusive();
+
     test_savedc();
     test_savedc_2();
     test_GdiConvertToDevmodeW();
diff --git a/dlls/gdi32/tests/font.c b/dlls/gdi32/tests/font.c
index d143949..d71ff34 100644
--- a/dlls/gdi32/tests/font.c
+++ b/dlls/gdi32/tests/font.c
@@ -2397,6 +2397,8 @@ static void test_GetTextFace(void)
 
 START_TEST(font)
 {
+    winetest_exclusive();
+
     init();
 
     test_logfont();
diff --git a/dlls/gdi32/tests/metafile.c b/dlls/gdi32/tests/metafile.c
index 5f295bb..801ca89 100644
--- a/dlls/gdi32/tests/metafile.c
+++ b/dlls/gdi32/tests/metafile.c
@@ -2152,6 +2152,8 @@ static void test_SetEnhMetaFileBits(void)
 
 START_TEST(metafile)
 {
+    winetest_exclusive();
+
     init_function_pointers();
 
     /* For enhanced metafiles (enhmfdrv) */
diff --git a/dlls/gdiplus/tests/font.c b/dlls/gdiplus/tests/font.c
index 0487655..80022e7 100644
--- a/dlls/gdiplus/tests/font.c
+++ b/dlls/gdiplus/tests/font.c
@@ -289,6 +289,8 @@ START_TEST(font)
     struct GdiplusStartupInput gdiplusStartupInput;
     ULONG_PTR gdiplusToken;
 
+    winetest_exclusive();
+
     gdiplusStartupInput.GdiplusVersion              = 1;
     gdiplusStartupInput.DebugEventCallback          = NULL;
     gdiplusStartupInput.SuppressBackgroundThread    = 0;
diff --git a/dlls/gdiplus/tests/image.c b/dlls/gdiplus/tests/image.c
index 38a58b9..0540d24 100644
--- a/dlls/gdiplus/tests/image.c
+++ b/dlls/gdiplus/tests/image.c
@@ -512,6 +512,8 @@ START_TEST(image)
     struct GdiplusStartupInput gdiplusStartupInput;
     ULONG_PTR gdiplusToken;
 
+    winetest_exclusive();
+
     gdiplusStartupInput.GdiplusVersion              = 1;
     gdiplusStartupInput.DebugEventCallback          = NULL;
     gdiplusStartupInput.SuppressBackgroundThread    = 0;
diff --git a/dlls/imm32/tests/imm32.c b/dlls/imm32/tests/imm32.c
index 591feb3..a1e5e47 100644
--- a/dlls/imm32/tests/imm32.c
+++ b/dlls/imm32/tests/imm32.c
@@ -221,6 +221,8 @@ static int test_ImmNotifyIME(void) {
 }
 
 START_TEST(imm32) {
+    winetest_exclusive();
+
     if (init())
         test_ImmNotifyIME();
     cleanup();
diff --git a/dlls/kernel32/tests/thread.c b/dlls/kernel32/tests/thread.c
index d1ac617..386f894 100644
--- a/dlls/kernel32/tests/thread.c
+++ b/dlls/kernel32/tests/thread.c
@@ -1224,6 +1224,8 @@ START_TEST(thread)
        return;
    }
 
+   winetest_exclusive();
+
    test_CreateRemoteThread();
    test_CreateThread_basic();
    test_CreateThread_suspended();
diff --git a/dlls/mshtml/tests/htmldoc.c b/dlls/mshtml/tests/htmldoc.c
index 5e95448..08d9139 100644
--- a/dlls/mshtml/tests/htmldoc.c
+++ b/dlls/mshtml/tests/htmldoc.c
@@ -4092,6 +4092,8 @@ static void gecko_installer_workaround(BOOL disable)
 
 START_TEST(htmldoc)
 {
+    winetest_exclusive();
+
     gecko_installer_workaround(TRUE);
 
     CoInitialize(NULL);
diff --git a/dlls/ole32/tests/compobj.c b/dlls/ole32/tests/compobj.c
index b2aaa22..677ec64 100644
--- a/dlls/ole32/tests/compobj.c
+++ b/dlls/ole32/tests/compobj.c
@@ -1021,6 +1021,9 @@ static void test_CoGetObjectContext(void)
 START_TEST(compobj)
 {
     HMODULE hOle32 = GetModuleHandle("ole32");
+
+    winetest_exclusive();
+
     pCoGetObjectContext = (void*)GetProcAddress(hOle32, "CoGetObjectContext");
     if (!(pCoInitializeEx = (void*)GetProcAddress(hOle32, "CoInitializeEx")))
     {
diff --git a/dlls/ole32/tests/marshal.c b/dlls/ole32/tests/marshal.c
index fba8b14..74bfd2a 100644
--- a/dlls/ole32/tests/marshal.c
+++ b/dlls/ole32/tests/marshal.c
@@ -2995,6 +2995,8 @@ START_TEST(marshal)
         return;
     }
 
+    winetest_exclusive();
+
     register_test_window();
 
     test_cocreateinstance_proxy();
diff --git a/dlls/opengl32/tests/opengl.c b/dlls/opengl32/tests/opengl.c
index e72d1a0..9d1dfc1 100644
--- a/dlls/opengl32/tests/opengl.c
+++ b/dlls/opengl32/tests/opengl.c
@@ -432,6 +432,8 @@ START_TEST(opengl)
         0, 0, 0                /* layer masks */
     };
 
+    winetest_exclusive();
+
     hwnd = CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW,
                         10, 10, 200, 200, NULL, NULL, NULL, NULL);
     ok(hwnd != NULL, "err: %d\n", GetLastError());
diff --git a/dlls/qmgr/tests/enum_files.c b/dlls/qmgr/tests/enum_files.c
index eeb8009..aca563a 100644
--- a/dlls/qmgr/tests/enum_files.c
+++ b/dlls/qmgr/tests/enum_files.c
@@ -279,6 +279,8 @@ START_TEST(enum_files)
     };
     const test_t *test;
 
+    winetest_exclusive();
+
     CoInitialize(NULL);
     for (test = tests; *test; ++test)
     {
diff --git a/dlls/qmgr/tests/enum_jobs.c b/dlls/qmgr/tests/enum_jobs.c
index f95404c..9bde1d1 100644
--- a/dlls/qmgr/tests/enum_jobs.c
+++ b/dlls/qmgr/tests/enum_jobs.c
@@ -307,6 +307,8 @@ START_TEST(enum_jobs)
     };
     const test_t *test;
 
+    winetest_exclusive();
+
     CoInitialize(NULL);
     for (test = tests; *test; ++test)
     {
diff --git a/dlls/qmgr/tests/file.c b/dlls/qmgr/tests/file.c
index 033b2c5..70ab3c6 100644
--- a/dlls/qmgr/tests/file.c
+++ b/dlls/qmgr/tests/file.c
@@ -177,6 +177,8 @@ START_TEST(file)
     };
     const test_t *test;
 
+    winetest_exclusive();
+
     CoInitialize(NULL);
     for (test = tests; *test; ++test)
     {
diff --git a/dlls/qmgr/tests/job.c b/dlls/qmgr/tests/job.c
index 36201f8..cb58391 100644
--- a/dlls/qmgr/tests/job.c
+++ b/dlls/qmgr/tests/job.c
@@ -498,6 +498,8 @@ START_TEST(job)
     };
     const test_t *test;
 
+    winetest_exclusive();
+
     if (!init_paths())
         return;
 
diff --git a/dlls/qmgr/tests/qmgr.c b/dlls/qmgr/tests/qmgr.c
index 8c95586..d30f753 100644
--- a/dlls/qmgr/tests/qmgr.c
+++ b/dlls/qmgr/tests/qmgr.c
@@ -231,6 +232,8 @@ START_TEST(qmgr)
         do_child(argv[2]);
     else
     {
+        winetest_exclusive();
+
         test_CreateInstance();
         test_CreateJob();
         test_EnumJobs();
diff --git a/dlls/riched20/tests/richole.c b/dlls/riched20/tests/richole.c
index 6eefdd0..5107ef8 100644
--- a/dlls/riched20/tests/richole.c
+++ b/dlls/riched20/tests/richole.c
@@ -60,6 +60,8 @@ START_TEST(richole)
   HRESULT hres;
   LRESULT res;
   HWND w;
+ 
+  winetest_exclusive();
 
   /* Must explicitly LoadLibrary(). The test has no references to functions in
    * RICHED20.DLL, so the linker doesn't actually link to it. */
diff --git a/dlls/shdocvw/tests/webbrowser.c b/dlls/shdocvw/tests/webbrowser.c
index 86d38db..6ba9586 100644
--- a/dlls/shdocvw/tests/webbrowser.c
+++ b/dlls/shdocvw/tests/webbrowser.c
@@ -2069,6 +2069,8 @@ static void gecko_installer_workaround(BOOL disable)
 
 START_TEST(webbrowser)
 {
+    winetest_exclusive();
+
     gecko_installer_workaround(TRUE);
 
     container_hwnd = create_container_window();
diff --git a/dlls/shell32/tests/systray.c b/dlls/shell32/tests/systray.c
index c672d67..56ea316 100644
--- a/dlls/shell32/tests/systray.c
+++ b/dlls/shell32/tests/systray.c
@@ -138,6 +138,8 @@ START_TEST(systray)
     RECT rc;
     HMODULE huser32, hshell32;
 
+    winetest_exclusive();
+
     hshell32 = GetModuleHandleA("shell32.dll");
     pShell_NotifyIconW = (void*)GetProcAddress(hshell32, "Shell_NotifyIconW");
 
diff --git a/dlls/shlwapi/tests/shreg.c b/dlls/shlwapi/tests/shreg.c
index 77a47e2..f529d21 100644
--- a/dlls/shlwapi/tests/shreg.c
+++ b/dlls/shlwapi/tests/shreg.c
@@ -378,8 +378,11 @@ static void test_SHDeleteKey(void)
 
 START_TEST(shreg)
 {
-	HKEY hkey = create_test_entries();
+	HKEY hkey;
 
+        winetest_exclusive();
+
+	hkey = create_test_entries();
         if (!hkey) return;
 
 	hshlwapi = GetModuleHandleA("shlwapi.dll");
diff --git a/dlls/user32/tests/broadcast.c b/dlls/user32/tests/broadcast.c
index c88cee7..7531921 100644
--- a/dlls/user32/tests/broadcast.c
+++ b/dlls/user32/tests/broadcast.c
@@ -333,6 +333,8 @@ static void test_noprivileges(void)
 
 START_TEST(broadcast)
 {
+    winetest_exclusive();
+
     if (!init_procs())
         return;
 
diff --git a/dlls/user32/tests/class.c b/dlls/user32/tests/class.c
index 8412e8b..caf5864 100644
--- a/dlls/user32/tests/class.c
+++ b/dlls/user32/tests/class.c
@@ -829,6 +829,8 @@ static void WINAPI CreateDialogParamTest(HINSTANCE hInstance)
 
 START_TEST(class)
 {
+    winetest_exclusive();
+
     HANDLE hInstance = GetModuleHandleA( NULL );
 
     if (!GetModuleHandleW(0))
diff --git a/dlls/user32/tests/clipboard.c b/dlls/user32/tests/clipboard.c
index 30b1707..84ee658 100644
--- a/dlls/user32/tests/clipboard.c
+++ b/dlls/user32/tests/clipboard.c
@@ -192,6 +192,8 @@ todo_wine
 
 START_TEST(clipboard)
 {
+    winetest_exclusive();
+
     SetLastError(0xdeadbeef);
     FindAtomW(NULL);
     if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) is_win9x = TRUE;
diff --git a/dlls/user32/tests/combo.c b/dlls/user32/tests/combo.c
index d47ff20..dd65dec 100644
--- a/dlls/user32/tests/combo.c
+++ b/dlls/user32/tests/combo.c
@@ -354,6 +354,8 @@ static void test_WM_LBUTTONDOWN(void)
 
 START_TEST(combo)
 {
+    winetest_exclusive();
+
     hMainWnd = CreateWindow("static", "Test", WS_OVERLAPPEDWINDOW, 10, 10, 300, 300, NULL, NULL, NULL, 0);
     ShowWindow(hMainWnd, SW_SHOW);
 
diff --git a/dlls/user32/tests/cursoricon.c b/dlls/user32/tests/cursoricon.c
index e00c45e..e233a9b 100644
--- a/dlls/user32/tests/cursoricon.c
+++ b/dlls/user32/tests/cursoricon.c
@@ -948,6 +948,8 @@ START_TEST(cursoricon)
         return;
     }
 
+    winetest_exclusive();
+
     test_CopyImage_Bitmap(1);
     test_CopyImage_Bitmap(4);
     test_CopyImage_Bitmap(8);
diff --git a/dlls/user32/tests/dce.c b/dlls/user32/tests/dce.c
index fead385..c0560dd 100644
--- a/dlls/user32/tests/dce.c
+++ b/dlls/user32/tests/dce.c
@@ -396,6 +396,8 @@ START_TEST(dce)
 {
     WNDCLASSA cls;
 
+    winetest_exclusive();
+
     cls.style = CS_DBLCLKS;
     cls.lpfnWndProc = DefWindowProcA;
     cls.cbClsExtra = 0;
diff --git a/dlls/user32/tests/dde.c b/dlls/user32/tests/dde.c
index 56c8893..88e93fd 100644
--- a/dlls/user32/tests/dde.c
+++ b/dlls/user32/tests/dde.c
@@ -2102,6 +2102,8 @@ START_TEST(dde)
         return;
     }
 
+    winetest_exclusive();
+
     ZeroMemory(&startup, sizeof(STARTUPINFO));
     sprintf(buffer, "%s dde ddeml", argv[0]);
     startup.cb = sizeof(startup);
diff --git a/dlls/user32/tests/dialog.c b/dlls/user32/tests/dialog.c
index 8bf3c29..ae9b7e4 100644
--- a/dlls/user32/tests/dialog.c
+++ b/dlls/user32/tests/dialog.c
@@ -923,6 +923,8 @@ static void test_DisabledDialogTest(void)
 
 START_TEST(dialog)
 {
+    winetest_exclusive();
+
     g_hinst = GetModuleHandleA (0);
 
     if (!RegisterWindowClasses()) assert(0);
diff --git a/dlls/user32/tests/edit.c b/dlls/user32/tests/edit.c
index 0c5a678..0df1a54 100644
--- a/dlls/user32/tests/edit.c
+++ b/dlls/user32/tests/edit.c
@@ -1991,6 +1991,8 @@ static void UnregisterWindowClasses (void)
 
 START_TEST(edit)
 {
+    winetest_exclusive();
+
     hinst = GetModuleHandleA(NULL);
     assert(RegisterWindowClasses());
 
diff --git a/dlls/user32/tests/input.c b/dlls/user32/tests/input.c
index 37198d3..bc5f70d 100644
--- a/dlls/user32/tests/input.c
+++ b/dlls/user32/tests/input.c
@@ -1167,6 +1167,8 @@ static void test_key_map(void)
 
 START_TEST(input)
 {
+    winetest_exclusive();
+
     init_function_pointers();
 
     if (!pSendInput)
diff --git a/dlls/user32/tests/listbox.c b/dlls/user32/tests/listbox.c
index 849372c..263c76a 100644
--- a/dlls/user32/tests/listbox.c
+++ b/dlls/user32/tests/listbox.c
@@ -1509,6 +1509,8 @@ START_TEST(listbox)
      {     2,      2,      2, LB_ERR}, {0,0,0,0},
      {LB_ERR, LB_ERR,      0, LB_ERR}, {0,0,0,0}};
 
+  winetest_exclusive();
+
   trace (" Testing single selection...\n");
   check (SS);
   trace (" ... with NOSEL\n");
diff --git a/dlls/user32/tests/menu.c b/dlls/user32/tests/menu.c
index 1aa2eb6..4392115 100644
--- a/dlls/user32/tests/menu.c
+++ b/dlls/user32/tests/menu.c
@@ -2340,6 +2340,8 @@ static void test_InsertMenu(void)
 
 START_TEST(menu)
 {
+    winetest_exclusive();
+
     init_function_pointers();
 
     register_menu_check_class();
diff --git a/dlls/user32/tests/msg.c b/dlls/user32/tests/msg.c
index dfb6108..12f4418 100644
--- a/dlls/user32/tests/msg.c
+++ b/dlls/user32/tests/msg.c
@@ -10918,6 +10918,8 @@ START_TEST(msg)
     BOOL ret;
     FARPROC pIsWinEventHookInstalled = 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
 
+    winetest_exclusive();
+
     init_procs();
 
     if (!RegisterWindowClasses()) assert(0);
diff --git a/dlls/user32/tests/scroll.c b/dlls/user32/tests/scroll.c
index 3bc407a..4dfd46a 100644
--- a/dlls/user32/tests/scroll.c
+++ b/dlls/user32/tests/scroll.c
@@ -131,6 +131,8 @@ START_TEST ( scroll )
 {
     WNDCLASSA wc;
 
+    winetest_exclusive();
+
     wc.style = CS_HREDRAW | CS_VREDRAW;
     wc.cbClsExtra = 0;
     wc.cbWndExtra = 0;
diff --git a/dlls/user32/tests/static.c b/dlls/user32/tests/static.c
index 7810db4..9381c96 100644
--- a/dlls/user32/tests/static.c
+++ b/dlls/user32/tests/static.c
@@ -99,6 +99,8 @@ START_TEST(static)
     static char szClassName[] = "testclass";
     WNDCLASSEX  wndclass;
 
+    winetest_exclusive();
+
     wndclass.cbSize         = sizeof(wndclass);
     wndclass.style          = CS_HREDRAW | CS_VREDRAW;
     wndclass.lpfnWndProc    = WndProc;
diff --git a/dlls/user32/tests/sysparams.c b/dlls/user32/tests/sysparams.c
index f899dab..45789cc 100644
--- a/dlls/user32/tests/sysparams.c
+++ b/dlls/user32/tests/sysparams.c
@@ -2660,6 +2660,8 @@ START_TEST(sysparams)
     DWORD dwThreadId;
     HANDLE hInstance, hdll;
 
+    winetest_exclusive();
+
     hdll = GetModuleHandleA("user32.dll");
     pChangeDisplaySettingsExA=(void*)GetProcAddress(hdll, "ChangeDisplaySettingsExA");
 
diff --git a/dlls/user32/tests/text.c b/dlls/user32/tests/text.c
index 1e09650..d8ab589 100644
--- a/dlls/user32/tests/text.c
+++ b/dlls/user32/tests/text.c
@@ -307,6 +307,8 @@ static void test_DrawState(void)
 
 START_TEST(text)
 {
+    winetest_exclusive();
+
     test_TabbedText();
     test_DrawTextCalcRect();
     test_DrawState();
diff --git a/dlls/user32/tests/win.c b/dlls/user32/tests/win.c
index 6cb784f..3cce45d 100644
--- a/dlls/user32/tests/win.c
+++ b/dlls/user32/tests/win.c
@@ -4805,6 +4805,8 @@ static void test_hwnd_message(void)
 
 START_TEST(win)
 {
+    winetest_exclusive();
+
     pGetAncestor = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" );
     pGetWindowInfo = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetWindowInfo" );
     pGetWindowModuleFileNameA = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetWindowModuleFileNameA" );
diff --git a/dlls/user32/tests/winstation.c b/dlls/user32/tests/winstation.c
index 42f2644..baeaeb2 100644
--- a/dlls/user32/tests/winstation.c
+++ b/dlls/user32/tests/winstation.c
@@ -350,6 +350,8 @@ static void test_enumdesktops(void)
 
 START_TEST(winstation)
 {
+    winetest_exclusive();
+
     /* Check whether this platform supports WindowStation calls */
 
     SetLastError( 0xdeadbeef );
diff --git a/dlls/usp10/tests/usp10.c b/dlls/usp10/tests/usp10.c
index 0705904..e2e74ff 100644
--- a/dlls/usp10/tests/usp10.c
+++ b/dlls/usp10/tests/usp10.c
@@ -1378,6 +1378,8 @@ START_TEST(usp10)
 
     unsigned short  pwOutGlyphs[256];
 
+    winetest_exclusive();
+
     /* We need a valid HDC to drive a lot of Script functions which requires the following    *
      * to set up for the tests.                                                               */
     hwnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,
diff --git a/dlls/uxtheme/tests/system.c b/dlls/uxtheme/tests/system.c
index ef9c08a..6267980 100644
--- a/dlls/uxtheme/tests/system.c
+++ b/dlls/uxtheme/tests/system.c
@@ -480,6 +480,8 @@ static void test_CloseThemeData(void)
 
 START_TEST(system)
 {
+    winetest_exclusive();
+
     if(!InitFunctionPtrs())
         return;
 
diff --git a/include/wine/test.h b/include/wine/test.h
index 02fc391..7319e8a 100644
--- a/include/wine/test.h
+++ b/include/wine/test.h
@@ -61,6 +61,7 @@ extern int winetest_loop_todo(void);
 extern void winetest_end_todo( const char* platform );
 extern int winetest_get_mainargs( char*** pargv );
 extern void winetest_wait_child_process( HANDLE process );
+extern void winetest_exclusive(void);
 
 #ifdef STANDALONE
 #define START_TEST(name) \
@@ -215,6 +216,41 @@ static tls_data* get_tls_data(void)
     return data;
 }
 
+/* Call this function near the top of the START_TEST() block 
+ * for tests that can't run in parallel with other tests.
+ * This will block other tests that also require those resources from
+ * running until this process exits.
+ * If locking fails for some reason, the function simply returns.
+ */
+void winetest_exclusive(void)
+{
+    HANDLE hLockfile;
+    OVERLAPPED overlap;
+    char filename[1024];
+
+    if (!GetTempPathA(sizeof(filename), filename))
+        return;
+
+    strcat(filename, "\\winetest.lck");
+    hLockfile = CreateFileA( filename, GENERIC_READ | GENERIC_WRITE,
+                          FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
+                          CREATE_ALWAYS, 0, 0 );
+    if (hLockfile == INVALID_HANDLE_VALUE)
+        return;
+
+    memset(&overlap, 0, sizeof(overlap));
+    /* Sigh. Wine doesn't support blocking LockFileEx yet; you have to use an event. */
+    overlap.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
+    /* You have to tell win32 that this event is not for completion */
+    overlap.hEvent = (HANDLE) ((DWORD) (overlap.hEvent) | 1);
+    if (LockFileEx( hLockfile, LOCKFILE_EXCLUSIVE_LOCK, 0, 1, 0, &overlap )) {
+        WaitForSingleObjectEx(overlap.hEvent, INFINITE, FALSE);
+        CloseHandle(overlap.hEvent);
+    }
+
+    /* CloseHandle(hLockfile); Leak the handle for now, else lock is released? */
+}
+
 static void exit_process( int code )
 {
     fflush( stdout );


Reply via email to