elements icon indicating copy to clipboard operation
elements copied to clipboard

MultiThreading using join freezes the entire GUI.

Open ahmedtalaat327 opened this issue 3 years ago • 4 comments

I noticed when I use More than one thread inside events like button for ex .. My Whole window freeze Even with the view.post timer is just async method not working..! Is there is method like signal in Qt to solve this issue or other method for view I dont know?

ahmedtalaat327 avatar Jul 05 '21 20:07 ahmedtalaat327

Could you post an MVCE?

djowel avatar Jul 05 '21 23:07 djowel

@djowel Ok at first I have a method called gateData(int case); derived from class called Scan
This method can handle about 50 thread in a concurrency way to minimize the time that the program needs timers can't do it with same way, When I call the method inside button click scanbtn.on_click like this: scanbtn.on_click =

&view_, &_app, scanbtn, mbc,&refreshbtn, &_win mutable { if (scanbtn._acive) {

view_.remove(mbc); //putting message auto msg_box = make_message(); view_.add((msg_box)); /////////////////////////////////////////////////--loading--////////////////////////////////////////// #if defined(WIN32) view.post(1s, [&view_,&_app,&refreshbtn,msg_box] { string akno[20]; string imgs[20]; int akno_size = 0; //------scan object---- Scan scan; //All threads goes here... scan.gateData(0); //scan.macs_net; akno_size = scan.ips_net.size(); . . .

it hangs cause of join that I'm using inside each loop of threads like this:

if (gateCase == 0) { std::vectorstd::thread threads0; for (int i = 0; i < s0p0.size(); i++) { const char* c = s0p0[i].c_str(); // auto r = std::thread(&Scan::loadTracing_Ip, this, c);

threads0.push_back(

std::thread([this, c] { //Code Scan::loadTracing_Ip(c); })

);

}

for (auto& th : threads0) { th.join(); }

ahmedtalaat327 avatar Jul 06 '21 19:07 ahmedtalaat327

More than thing ..The window actually freezes for a seconds (you cant interact with any of it's components) then works perfect.

ahmedtalaat327 avatar Jul 06 '21 19:07 ahmedtalaat327

The only way I can help is if you post an MVCE: https://stackoverflow.com/help/minimal-reproducible-example

djowel avatar Jul 06 '21 22:07 djowel