Intel TBB file access

114 Views Asked by At

I am learning to use the Intel TBB library but have run into a weird error. My source node reads data in from a file using fstream but if I try to close the fstream in the class destructor, the program seg faults. Does anyone know why you can't close a file stream in the destructor of a source node class while using Intel TBB? Also what would be the fix so I can properly close the file after it is done reading?

1

There are 1 best solutions below

0
dokis On

It's hard to tell without a source code, but in cases like this, it is often a problem with object lifetime. When you submit a TBB task for execution, it will be executed at some later point in time, determined by the TBB task scheduler. If such task references an object (via pointer or reference), you need to make sure that the referenced object is still valid (not destroyed) when the task executes.