buffered_channel calls deleter twice when using iterators
- Ngôn ngữ chính
- C++
- Star
- 510
- Fork
- 123
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
version: 1.75.0 (probably 1.78.0)
compiler: gcc 9.4.0
Hi, I have found some unexpected behavior when using ```buffered_channel::iterator```. The destructor is called twice when using them.
This happens first time when ```operator++``` is called and second time in ```increment()```
https://github.com/boostorg/fiber/blob/8d0fe6055ad2c2cd98a022ad663d2bbd42e056c9/include/boost/fiber/buffered_channel.hpp#L357-L361
https://github.com/boostorg/fiber/blob/8d0fe6055ad2c2cd98a022ad663d2bbd42e056c9/include/boost/fiber/buffered_channel.hpp#L310-L320
Got this on version 1.75.0 but it seems that it is still present.
Minimal reproducible example:
```cpp
#include
#include
#include
class Foo
{
public:
Foo(int i) : i_(i) {std::cout << "Foo()\n";}
~Foo() {std::cout << "~Foo()\n";}
void PrintI() {std::cout << "Foo::operator()(): " << i_ << "\n";}
private:
int i_ = 0;
};
using FooSptr = std::shared_ptr;
int main(int, char**)
{
boost::fibers::buffered_channel chan(16);
boost::fibers::fiber f([&]() {
std::vector fooVec; // keep objects for some time
for(auto& foo : chan)
{
fooVec.push_back(foo);
}
for (auto& foo : fooVec)
{
foo->PrintI();
}
fooVec.clear();
std::cout << "Fiber finished\n";
});
chan.push(std::make_shared(0));
chan.push(std::make_shared(1));
chan.close();
std::cout << "chan.close();\n";
f.join();
return 0;
}
```
In this example I pass some shared_ptr's through the channel and put it in an array to extend it's lifetime. But counter decrements twice and objects gets destroyed.
Expected result:
```
Foo()
Foo()
chan.close();
Foo::operator()(): 0
Foo::operator()(): 1
~Foo()
~Foo()
Fiber finished
```
Actual result:
```
Foo()
Foo()
chan.close();
~Foo()
~Foo()
Foo::operator()(): 32
Foo::operator()(): 1953066354
Fiber finished
```
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Đánh giá
Issue này chưa được đánh giá.