Index: /trunk/src/VBox/Additions/common/crOpenGL/context.c
===================================================================
--- /trunk/src/VBox/Additions/common/crOpenGL/context.c	(revision 37985)
+++ /trunk/src/VBox/Additions/common/crOpenGL/context.c	(revision 37986)
@@ -497,6 +497,6 @@
 
 void
-stubGetWindowGeometry( const WindowInfo *window, int *x, int *y,
-                                             unsigned int *w, unsigned int *h )
+stubGetWindowGeometry(const WindowInfo *window, int *x, int *y,
+                      unsigned int *w, unsigned int *h )
 {
     RECT rect;
@@ -1133,4 +1133,7 @@
         return;
     }
+
+    crHashtableLock(stub.contextTable);
+
     context = (ContextInfo *) crHashtableSearch(stub.contextTable, contextId);
 
@@ -1167,6 +1170,7 @@
     crMemZero(context, sizeof(ContextInfo));  /* just to be safe */
     crHashtableDelete(stub.contextTable, contextId, crFree);
-}
-
+
+    crHashtableUnlock(stub.contextTable);
+}
 
 void
Index: /trunk/src/VBox/Additions/common/crOpenGL/glx.c
===================================================================
--- /trunk/src/VBox/Additions/common/crOpenGL/glx.c	(revision 37985)
+++ /trunk/src/VBox/Additions/common/crOpenGL/glx.c	(revision 37986)
@@ -682,5 +682,9 @@
     }
 
-    if (ctx && drawable) {
+    if (ctx && drawable)
+    {
+        crHashtableLock(stub.windowTable);
+        crHashtableLock(stub.contextTable);
+
         context = (ContextInfo *) crHashtableSearch(stub.contextTable, (unsigned long) ctx);
         window = stubGetWindowInfo(dpy, drawable);
@@ -692,5 +696,6 @@
         }
     }
-    else {
+    else
+    {
         dpy = NULL;
         window = NULL;
@@ -702,4 +707,11 @@
 
     retVal = stubMakeCurrent(window, context);
+
+    if (ctx && drawable)
+    {
+        crHashtableUnlock(stub.contextTable);
+        crHashtableUnlock(stub.windowTable);
+    }
+
     return retVal;
 }
Index: /trunk/src/VBox/Additions/common/crOpenGL/icd_drv.c
===================================================================
--- /trunk/src/VBox/Additions/common/crOpenGL/icd_drv.c	(revision 37985)
+++ /trunk/src/VBox/Additions/common/crOpenGL/icd_drv.c	(revision 37986)
@@ -95,17 +95,21 @@
     ContextInfo *context;
     WindowInfo *window;
+    BOOL ret;
 
     /*crDebug( "DrvSetContext called(0x%x, 0x%x)", hdc, hglrc );*/
     (void) (callback);
 
+    crHashtableLock(stub.windowTable);
+    crHashtableLock(stub.contextTable);
+
     context = (ContextInfo *) crHashtableSearch(stub.contextTable, (unsigned long) hglrc);
     window = stubGetWindowInfo(hdc);
 
-    if (stubMakeCurrent( window, context )) {
-        return &icdTable;
-    }
-    else {
-        return NULL;
-    }
+    ret = stubMakeCurrent(window, context);
+
+    crHashtableUnlock(stub.contextTable);
+    crHashtableUnlock(stub.windowTable);
+
+    return ret ? &icdTable:NULL;
 }
 
Index: /trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_misc.c
===================================================================
--- /trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_misc.c	(revision 37985)
+++ /trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_misc.c	(revision 37986)
@@ -104,8 +104,11 @@
 }
 
+#define PACK_FORCED_SYNC
+
 void PACKSPU_APIENTRY packspu_Flush( void )
 {
     GET_THREAD(thread);
     int writeback = 1;
+    int found=0;
 
     if (!thread->bInjectThread)
@@ -126,18 +129,37 @@
         crLockMutex(&_PackMutex);
 
-        /*Make sure we process commands in order they should appear, so flush thread being injected first*/
+        /*Make sure we process commands in order they should appear, so flush other threads first*/
         for (i=0; i<MAX_THREADS; ++i)
         {
             if (pack_spu.thread[i].inUse
                 && (thread != &pack_spu.thread[i]) && pack_spu.thread[i].netServer.conn
-                && (pack_spu.thread[i].netServer.conn->u32ClientID == thread->netServer.conn->u32InjectClientID)
                 && pack_spu.thread[i].packer && pack_spu.thread[i].packer->currentBuffer)
             {
+#ifdef PACK_FORCED_SYNC
+            	CRPackContext *pc = pack_spu.thread[i].packer;
+            	unsigned char *data_ptr;
+
+            	CR_GET_BUFFERED_POINTER( pc, 16 );
+            	WRITE_DATA( 0, GLint, 16 );
+            	WRITE_DATA( 4, GLenum, CR_WRITEBACK_EXTEND_OPCODE );
+            	WRITE_NETWORK_POINTER( 8, (void *) &writeback );
+            	WRITE_OPCODE( pc, CR_EXTEND_OPCODE );
+            	CR_UNLOCK_PACKER_CONTEXT(pc);
+#endif
                 packspuFlush((void *) &pack_spu.thread[i]);
-                break;
+
+                if (pack_spu.thread[i].netServer.conn->u32ClientID == thread->netServer.conn->u32InjectClientID)
+                {
+                    found=1;
+                }
+
+#ifdef PACK_FORCED_SYNC
+                while (writeback)
+                    crNetRecv();
+#endif
             }
         }
 
-        if (i>=MAX_THREADS)
+        if (!found)
         {
             /*Thread we're supposed to inject commands for has been detached,
@@ -147,7 +169,15 @@
         }
 
+#ifdef PACK_FORCED_SYNC
+        writeback = 1;
+        crPackWriteback(&writeback);
+#endif
+        packspuFlush((void *) thread);
+
+#ifdef PACK_FORCED_SYNC
+        while (writeback)
+            crNetRecv();
+#endif
         crUnlockMutex(&_PackMutex);
-
-        packspuFlush((void *) thread);
     }
 }
Index: /trunk/src/VBox/Additions/common/crOpenGL/stub.c
===================================================================
--- /trunk/src/VBox/Additions/common/crOpenGL/stub.c	(revision 37985)
+++ /trunk/src/VBox/Additions/common/crOpenGL/stub.c	(revision 37986)
@@ -127,8 +127,8 @@
     if (winInfo && winInfo->type == CHROMIUM && stub.spu)
     {
+        crHashtableLock(stub.windowTable);
+
         stub.spu->dispatch_table.WindowDestroy( winInfo->spuWindow );
-#ifdef CR_NEWWINTRACK
-        crLockMutex(&stub.mutex);
-#endif
+
 #ifdef WINDOWS
         if (winInfo->hVisibleRegion != INVALID_HANDLE_VALUE)
@@ -147,10 +147,9 @@
         }
 # endif
-#endif
-#ifdef CR_NEWWINTRACK
-        crUnlockMutex(&stub.mutex);
 #endif
         crForcedFlush();
         crHashtableDelete(stub.windowTable, window, crFree);
+
+        crHashtableUnlock(stub.windowTable);
     }
 }
Index: /trunk/src/VBox/GuestHost/OpenGL/include/cr_hash.h
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/include/cr_hash.h	(revision 37985)
+++ /trunk/src/VBox/GuestHost/OpenGL/include/cr_hash.h	(revision 37986)
@@ -36,4 +36,6 @@
 /*Returns GL_TRUE if given hashtable hold the data, pKey is updated with key value for data in this case*/
 DECLEXPORT(GLboolean) crHashtableGetDataKey(CRHashTable *pHash, void *pData, unsigned long *pKey);
+DECLEXPORT(void) crHashtableLock(CRHashTable *h);
+DECLEXPORT(void) crHashtableUnlock(CRHashTable *h);
 
 #ifdef __cplusplus
Index: /trunk/src/VBox/GuestHost/OpenGL/util/hash.c
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/util/hash.c	(revision 37985)
+++ /trunk/src/VBox/GuestHost/OpenGL/util/hash.c	(revision 37986)
@@ -353,4 +353,17 @@
 }
 
+void crHashtableLock(CRHashTable *h)
+{
+#ifdef CHROMIUM_THREADSAFE
+    crLockMutex(&h->mutex);
+#endif
+}
+
+void crHashtableUnlock(CRHashTable *h)
+{
+#ifdef CHROMIUM_THREADSAFE
+    crUnlockMutex(&h->mutex);
+#endif
+}
 
 void crHashtableWalk( CRHashTable *hash, CRHashtableWalkCallback walkFunc , void *dataPtr2)
