- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would like to do the following.
For example I have some GUI application.
There is a button. If user press the button application runs some activity in bacground(in another thread).
After that the button is going to disable. And user can continue work with application(of course he can't click the button again, because it is disabled).
[cpp]class Activity : public tbb::task { public: virtual tbb::task* execute(); }; tbb::task* Activity::execute() { //here I do my work in backround. //What I should return??? } class Window { ..... void onButtonPress(); void onActivityFinished(); private Button* m_startNewTask; }; void Window::onButtonPress() { m_startNewTask->disable(); tbb::task activity = new Activity; tbb::task* thread = activity->execute(); } void Window::onActivityFinished() { m_startNewTask->enable(); } [/cpp]
The first quastion is situated in the comment
[cpp]What I should return??? Is it parent task, child task, null pointer.And the most important quastion. How to call onActivityFinished when task is finished the job?
[/cpp]
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
True.
I have some concern about using an automatic variable for tbb_thread. This object is destroyed when the method is complete, so the newly created thread is kind of "lost" - as far as I remember, it will be left in "detached" state which means it will run to completion but you can not join() it (i.e. can not check whether it has completed or not). I recommend you to double-check with the reference manual, and think whether the behavior is acceptable.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
For communication between the GUI thread and the worker thread, you could use events or messages or whatever stuff is available for that purpose in your programming platform.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Alexey,
It 's exactly what I want. I've just thought that there is some way to register callback or functor, that will be called when thread is finished.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Alexey, tbb_thread is the accaptable solution.
I've developed prototype using it and I am fine.
[bash]class Dialog : public gui::Window { public: Dialog() : m_startActivity(new gui::Button){} ~Dialog(){delete m_startActivity;} virtual bool enable() const{ return m_startActivity->enable(); } virtual void execute() { onButtonPressed(); } void onButtonPressed() { m_startActivity->enable(false); tbb::tbb_thread(engine::Acitivity(*m_startActivity)); } void onActivityFinished() { m_startActivity->enable(true); } private: gui::Button* m_startActivity; };[/bash]But I still have a qustion when code execution is reached tbb::tbb_thread(engine::Activity(*m_startActivity)) new thread will be created and engine::Activity::operato() will be called in new created thread, is it true?
{
public:
Dialog() : m_startActivity(new gui::Button){}
~Dialog(){delete m_startActivity;}
virtual bool enable() const{
return m_startActivity->enable();
}
virtual void execute() {
onButtonPressed();
}
void onButtonPressed() {
m_startActivity->enable(false);
tbb::tbb_thread(engine::Acitivity(*m_startActivity));
}
void onActivityFinished() {
m_startActivity->enable(true);
}
private:
gui::Button* m_startActivity;
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
True.
I have some concern about using an automatic variable for tbb_thread. This object is destroyed when the method is complete, so the newly created thread is kind of "lost" - as far as I remember, it will be left in "detached" state which means it will run to completion but you can not join() it (i.e. can not check whether it has completed or not). I recommend you to double-check with the reference manual, and think whether the behavior is acceptable.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page