I have two threads (io and otherIo is of boost asio io_context type).
Thread 1 (798c) | Thread 2 (681c)
---------- ---------
io.run() | otherIo.run()
From first thread i post an event where i make an object named "AnotherA" and run a function belonging to AnotherA class. AnotherA has a private variable name_ and a function called name() which just prints its name
io->post([=]()
{
AnotherA aobj(io, otherIo, "Kushina");
aobj.anotherExecute();
})
anotherExecute() function contains below code:
void anotherExecute()
{
name();
otherIo_->post(std::bind(&AnotherA::name, this));
}
Output:
--------
2021-05-04 19:08:37 [798c]<info> Constructor called!!!
2021-05-04 19:08:37 [798c]<info> My name is : Kushina, address: 00FAEB00
2021-05-04 19:08:37 [798c]<info> Destructor called !!!
2021-05-04 19:08:37 [681c]<info> My name is : Kushina, address: 00FAEB00
My question is:
How is the name getting printed second time even after the destructor is called ? If the bind overload i chose makes a copy of AnotherA object (which explains the 2nd print in 1st question) why is the destructor not getting called after the post event finishes running.Also, why is the address of "this" same for both.
name function:
void name()
{
log_info << "My name is : " << name_ << ", address: " << this;
}
Aucun commentaire:
Enregistrer un commentaire