- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm really not sure if this is a bug or not, it seems to be. The following code causes an assertion (compiled without optimizations):
Assertion 1L<state() & (1L<<:ALLOCATED>Aborted
Here's the code:
#include
#include
#include
class HelloTask : public tbb::task
{
public:
HelloTask(int depth) : _depth(depth) { }
tbb::task* execute()
{
if(_depth == 0) return 0;
HelloTask& a = *new ( allocate_child() ) HelloTask(_depth - 1);
HelloTask& b = *new ( allocate_child() ) HelloTask(_depth - 1);
set_ref_count(ref_count() + 1);
spawn(a);
set_ref_count(ref_count() + 1);
spawn(b);
int tmp;
for(int i = 0; i < 1000000; ++i)
{
tmp = tmp*i;
}
set_ref_count(ref_count() + 1);
wait_for_all();
return 0;
}
private:
int _depth;
};
int main()
{
tbb::task_scheduler_init init;
HelloTask& a = *new ( tbb::task::allocate_root() ) HelloTask(10);
tbb::task::spawn_root_and_wait(a);
}
Assertion 1L<
Here's the code:
#include
#include
#include
class HelloTask : public tbb::task
{
public:
HelloTask(int depth) : _depth(depth) { }
tbb::task* execute()
{
if(_depth == 0) return 0;
HelloTask& a = *new ( allocate_child() ) HelloTask(_depth - 1);
HelloTask& b = *new ( allocate_child() ) HelloTask(_depth - 1);
set_ref_count(ref_count() + 1);
spawn(a);
set_ref_count(ref_count() + 1);
spawn(b);
int tmp;
for(int i = 0; i < 1000000; ++i)
{
tmp = tmp*i;
}
set_ref_count(ref_count() + 1);
wait_for_all();
return 0;
}
private:
int _depth;
};
int main()
{
tbb::task_scheduler_init init;
HelloTask& a = *new ( tbb::task::allocate_root() ) HelloTask(10);
tbb::task::spawn_root_and_wait(a);
}
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Once you spawn a child, you must not use set_ref_count() again; use allocate_additional_child_of() instead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Raf Schietekat
Once you spawn a child, you must not use set_ref_count() again; use allocate_additional_child_of() instead.
Aha, thanks.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page