It probably has something to do with what getXyz() is doing, and/or what you are doing with "x". Definitely you should not continue to use "x" after the CoUninitialize().
Since you are calling CoInitialize() in a function from several threads, you need to be aware of three important facts:
1. Since you are calling CoInitialize() and not CoInitializeEx(), each of your threads is creating its own single-threaded apartment for any objects you create or marshal into the thread. You won't be able to share "x" or any other object/interface between threads without marshaling them. You may want to consider calling CoInitializeEx(NULL,COINIT_MULTITHREADED) instead.
2. Since you are calling CoInitialize() from a function, you should know that a thread can only call CoInitialize() once. Subsequent calls have no effect. So if your function is called more than once, it could be a problem. Generally, you should only call CoInitialize() and CoUninitialize() from your thread's main function, not any subroutines.
3. The first thread that calls CoInitialize() needs to be the last thread to call CoUninitialize(). According to the Microsoft documentation, if you don't do this, subsequent calls to CoInitialize() will fail and the application will not work.