wxThread: Windows vs *nix

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 5154
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

wxThread: Windows vs *nix

Post by ONEEYEMAN » Fri Apr 02, 2021 1:05 am

Hi, ALL,

Code: Select all

wxThread::ExistCode MyThread::Entry()
{
    while( !TestDestroy() )
     {
         std::lock_guard<std::mutex> loocker();
         int res = call_some_func();
         if( res )
             Delete();
     }
     return (wxThread::ExitCode) 0;
}
When I run this code on Windows (8.1/MSVC 2017) everything works as expected - thread ends successfully.
When I run it on Linux (GTK 3.24, C++11) - it does not. Thread does not ends.

Am I doing something wrong here?

Thank you.

User avatar
doublemax
Moderator
Moderator
Posts: 16014
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxThread: Windows vs *nix

Post by doublemax » Fri Apr 02, 2021 1:23 am

Calling Delete() from inside the thread itself is definitely unusual. Remove it (just use break) and check if it makes any difference.
Use the source, Luke!

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 5154
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxThread: Windows vs *nix

Post by ONEEYEMAN » Fri Apr 02, 2021 2:08 am

doublemax,
Yes it worked.
But now - where do I kill the thread? Or it will just die and all I will need is to delete the pointer?

Thank you.

User avatar
doublemax
Moderator
Moderator
Posts: 16014
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxThread: Windows vs *nix

Post by doublemax » Fri Apr 02, 2021 8:00 am

Detached threads delete themselves when they're done.
Use the source, Luke!

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 5154
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxThread: Windows vs *nix

Post by ONEEYEMAN » Fri Apr 02, 2021 11:51 am

doublemax,
I followed the code from wxThread docs and it looks like everything works. I'll try linux/mac today, but suspect everything will work there as well.

Thank you.

Post Reply