Hi, guys,
I want to run WxThreads in ONE thread because I want to write some data into a file for tracking. In case of multi-threads, the output file is messed up. I guess there are multiple threads writing into the output file.
Can I run wxThread with only ONE thread? How to do it if possible? Is there any way to dump data in case of only one thread running?
I look forward to your help and your reply is highly appreciated.
Thanks and Regards,
Dingjun
Can I specify the number of threads running for WxThread?
-
- Earned a small fee
- Posts: 16
- Joined: Wed Aug 23, 2023 9:05 pm
Re: Can I specify the number of threads running for WxThread?
It seems you need to learn how multi-threading works, each thread is separate, you cannot run "run WxThreads in ONE thread".
There is only as many threads as you create, wxWidgets does not create any on its own (or at least not visible to the user).
You seem to be looking either for a thread pool (which wxWidgets does not provide) or an access synchronization object, such as semaphore, mutex, or critical section, which wxWidgets has.
Regardless, it is not recommended to use wxThread and company in new code, they are relics from times C++ did not have multi-threading support.
There is only as many threads as you create, wxWidgets does not create any on its own (or at least not visible to the user).
You seem to be looking either for a thread pool (which wxWidgets does not provide) or an access synchronization object, such as semaphore, mutex, or critical section, which wxWidgets has.
Regardless, it is not recommended to use wxThread and company in new code, they are relics from times C++ did not have multi-threading support.
- shawnhcorey
- Knows some wx things
- Posts: 41
- Joined: Mon Nov 19, 2012 3:29 pm
- Location: The Great White North
Re: Can I specify the number of threads running for WxThread?
Usually, all the I/O is done in the main (aka root) thread to avoid these problems. Threads are used only for processing. They return their results to the main thread for output.
WARNING: Highly caffeinated
. Approach with caution
.