Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: C++11 std::thread and Firemonkey with Berlin


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 1 - Last Post: Feb 17, 2017 5:09 PM Last Post By: Remy Lebeau (Te...
Kyungshik Bang

Posts: 1
Registered: 7/26/13
C++11 std::thread and Firemonkey with Berlin  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 17, 2017 10:23 AM
Nowadays I'm testing c++11 features with firemonkey.
I just added a button on the form and coded as below.
Executed well in Window platform, but in Android, it crashes.
Am I doing something wrong?

....
#include <thread>
...
...
void __fastcall TForm1::Button1Click(TObject *Sender)
{
std::thread th(test);
th.detach();
}
//---------------------------------------------------------------------------
void TForm1::test()
{
int i = 0;
i++;
String t = IntToStr(i);
TThread::Queue(NULL, [this,t](){
ShowMessage(L"Hello World from thread " + t);
});
}
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: C++11 std::thread and Firemonkey with Berlin  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 17, 2017 5:09 PM   in response to: Kyungshik Bang in response to: Kyungshik Bang
Kyungshik wrote:

Executed well in Window platform, but in Android, it crashes.

Crashes where and how exactly? Please be more specific.

String t = IntToStr(i);
TThread::Queue(NULL, [this,t](){
ShowMessage(L"Hello World from thread " + t);
});

Why are you capturing 'this'? Why are you capturing 'i' as a String instead
of as-is?

Thread::Queue(nullptr, [i](){
    ShowMessage(L"Hello World from thread " + String(i));
});


--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02