so basically I am having problems when trying to run EdsDownloadEvfImage from the Canon EOS SDK on a separate thread. The program then does... unexpected things, freezes, etc.
Basically, what it does is that the worker thread freezes on EdsDownloadEvfImage when trying to lock a mutex from main thread, which is simply mind-blowing for me.
I've found out that doing any of the EdsOpenSession, EdsCreateMemoryStream, etc. on a thread is an absolute killer, but that doesn't mind, the only really time-consuming operation is that image download.
Based on the documenatation, I've ensured that the worker thread has
CoInitializeEx( NULL, COINIT_APARTMENTTHREADED )
called before the download. I've also tried it without it and it was without any difference. Maybe there's some problem with executing this function?
Or would a working alternative be running the entire EDSDK on a worker thread? (with initializeSDK etc.)
Thanks for reponses.
Btw: I'm using the SDK in a Qt application.
Problem solved, I just put everything on a separate thread and now it's working fine.
Related
I'm playing around with SLD2 and I've got a somewhat working game. It works great on Linux/Windows, but I'm getting an exception on macOS.
I've done input handling in a separate thread, basically it just polls for user input and then does calculations/moves sprites around etc. My problem is that on macOS it seems that the library is compiled in a way that when you call SDL_PollEvent, SDL_WaitEvent or SDL_HasEvents it calls SDL_PumpEvents from within itself, which can only be called from the main thread.
Is there a way to get the events without the functions calling SDL_PumpEvents? (I call that in main thread on every iteration, so it really isn't needed)
I'm on some c++ mobile product, but I need my apps main thread is still running without any blocking when doing some heavy work on the background thread and run back on main thread. But I realized there is no runOnMainThread/runOnUIThread in c++ thread api. I trying to figure it out the issue and found that need to depend library, or create your own thread event queue. Although it is good, but i am thinking to have a behavior which can runOnUIThread.
How it does not work: the mentioned library creates a timer, installs a SIGALRM signal handler and dispatches queued tasks when signals are fired. This allows tasks being processed on the main thread even when it is busy. However POSIX permits only a small set of async-signal-safe functions to be invoked inside of signal handler. Running arbitrary с++ code inside of signal handler violates that restriction and leaves application in hopelessly doomed state.
After some research and development, I've created a library called NonBlockpp
it is a small c++ library to allow c++ mobile application able to process the heavy and time consuming task on background and back to Main thread again, It’s been tested and fired the main thread event.
It also allow to save the tasks and fire them later, all the task has no blocking each other and thread safety.
How it works:
If you found any query or suggestion, please don't hesitate to raise an issue and we can discuss it together.
The project has rectify from signal to pollEvent due to signal handler might not be safe to use.
Please take a look the new changed.
NonBlockpp
Usage
I have some legacy code that launches Word (and other applications) from a C++ program using COM automation and the MSO dll. This runs on a server, non-interactively.
Occasionally the application will hang and eventually over many day/weeks, the resources on the server will be used up by many hung processes.
The process is launched:
Word::_ApplicationPtr wordApp
HRESULT hr = wordApp.CreateInstance(__uuidof(Word::Application));
various calls are then made via the wordApp pointer, one of which may hang. The code never returns form the call and the C++ code is stalled.
What is a solution to checking for these hangs and then killing off Word?
I have pondered using CreateProcess and using waitforsingleobject with a timeout but I cant then manipulate the object via automation.
I cant see a way of retrieving the handle to the COM launched app so cant kill it using that.
I thought about a separate thread and waiting on that then killing the thread after a timeout but killing a thread doesnt release all the resources i.e. word.
I thought about enumming all the active processes and searching for "winword" then killing every process that matched but this seems messy and a hack.
So anyone any ideas?
Thanks.
I have an iPhone app that is recording audio and then broadcasting it across the network. In response to a "stop" from the far end it queues a notification to stop the recording. Alas when it gets to the AudioQueueStop call the application just hangs (ie Stop never exits). Thanks to the notification all AudioQueue manipulation is happening on the same thread.
Has anyone got any idea whats going on here?
Edit: I have set up a listener in the UI thread that handles the recorder.
Then from my network thread I use a "postNotificationName" beliving that it was post a message to the UI thread and everything would run from that thread. This does not appear to be the case. When I break point the function that is called by the postNotificationName it appears that the call is being made on the networking thread and NOT on the UI Thread.
I assume this is my error. Anyone know how to make it work by notifying the UIThread to handle it?
Edit2: OK I've re-written it to use performSelectorOnMainThread. And it still crashes.
On the plus side I just learnt how to get a lot more info out of XCode so I can see the call stack goes:
semaphore_timedwait_signal_trap
semaphore_timedwait_signal
_pthread_cond_wait
pthread_cond_timedwait_relative_np
CAGuard::WaitFor
ClientAudioQueue::ServicePendingCallbacks
AudioQueueStop
[etc]
Anyone got any ideas why it hangs?
How do you call AudioQueueStop ? The function supports two modes: synchronous and asynchronous.
The preferred way is to use the asynchronous stopping as the function will return immediately, while the remaining buffers will be played/recorded.
If you want to go synchronous and you get a hang, then maybe there is a dead-lock or a race condition somewhere. Have you tried to pause the application under the debugger and check the threads' stack-frames to see where the problem is ?
What's the best/proper method to collect log messages from multiple threads and have them all be displayed using a window? (while the threads are running).
I am currently trying to redirect stdout (cout) in to a wxTextCtrl but failing miserably when attempting to do so over multiple threads. Any help would be appreciated.
Logging has had a few major updates recently in the wxWidgets trunk, you can read about them here. One of them is to add support for logging from threads other than the main thread.
In what way is it failing? I'm not familiar with the wxTextCtrl, but unless it has built in synchronization (ie. its thread safe) that could be a big issue. The simplest way to protect a single resource like this is via a named 'mutex'. The following example is what you can do in each thread to make sure that only one accesses this resource (the output window) at a time.
// In each thread's initialization:
HANDLE mutexHandle = CreateMutex(0,FALSE,"__my_protecting_mutex__");
// Whenever you use the debug output:
WaitForSingleObject(mutexHandle, /* Timeout if you like. */ 0xFFFFFFFF );
// Do our printing here.
ReleaseMutex(mutexHandle);
// In each thread's cleanup:
CloseHandle(mutexHandle);
So this basically guarantees that only one thread can be in between the wait and the release. Now if your issue is actually routing to the wxTextCtrl, I would need some more details.
Edit: I just realized that what I posted is Windows specific, and maybe you aren't on windows! If you aren't I don't have experience with other platform's synchronization methods, but boost has some generic libraries which are not platform specific.