Home » U++ Library support » U++ Library : Other (not classified elsewhere) » I request the implementation of callback5
Re: I request the implementation of callback5 [message #49821 is a reply to message #49820] |
Thu, 10 May 2018 19:15   |
Oblivion
Messages: 1215 Registered: August 2007
|
Senior Contributor |
|
|
Quote:What about thisback?
E,g
threads[free_index].Run ( THISBACK5 ( execute_bot_in_background, bot1, a, pick(params), result_mode, stat_group_id ) );
Use anonymous functions instead, that's the preferred way.
I'd either write the code as local anonymous function, or simply wrap it in a local anonymous function (lambda). That's analogous to what Callback does:
const int a = 10, b = 10;
Thread::Run([=]{ Cout() << a *b; }); // <- Use capture by value; (If you are going to capture by reference insted, be veyy careful, as this is a thread.
Or
Thread::Run([=]{ execute_bot_in_background(bot1, a, pick(params), result_mode, stat_group_id); });
As a side note: If you are working with threads, and you don't need dedicated threads but worker threads, I suggest using Upp::CoWork, or Upp::AsyncWork
They are much easier to use and control, and CAN give a greater performance, as they are optimized to be used as worker threads.
Just check their docs and reference examples.
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Thu, 10 May 2018 19:25] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Fri Jul 18 07:29:44 CEST 2025
Total time taken to generate the page: 0.00765 seconds
|