Recently the multithreading drives me crazy......
I have 3 main thread in the app.
1: message thread
2: network request pool
3: usb message thread
Thread 1 (message thread) calls a method to create a threadpoolJob to fetch content from network and use callback (normal pointer callback) to notify back to thread 1 again (not sure whether it's thread 1.... Question1), and then in the callback I control the UsbManager to do something (start listener etc)
and when app shutting down, it always tells me "Free Heap block xxx modified at xxx after it was freed"
so I set a waitableEvent for the manager class which own the thread 2 (network Jobs thread) deconstructor and let the class own UsbThread to set signal for the event after the usbthread stopped, so always keep the UsbManager(UsbThread) destroy first, and the error message no longer shows up again. (Question2)
so my question:
Q1: here the current thread is 2 or 1? I don't quit understand about resource destory (life cycle) on a thread.
Q2: why I need to control the destory sequence? again I think it's something about resource life on a thread...
Q3: I need some basic praticle on multi-threading, any suggestion? especially about resource control. (also thread synchronization, but lower priority)
I don't know if you guys could understand what I'm talking about.. sorry for the bad english.