New answers tagged

3

I think this code is very basic. I didn't look very deeply inside it and didn't bother to run it. I think I can give you some advices without it. I only looked at readability not efficiency, which when you are using standard c++ should be fine in most cases. You should usually be woried about efficiency only when you detect there is problem with it and it ...


1

Not that it is important, but pop and push both use unbounded loops to wait for other operations to finish. So strictly speaking your queue implementation is not lock-free. This can be a performance problem in case of oversubscription (i.e., when you use more threads than you have cores). However, with regards to performance improvements you should first ...


2

The following are only a few quick notes on the C++ language usage from a first reading. I didn't have enough time to fully get through the whole code (might revisit later) and make suggestions on the overall design. I hope this is still considered an ok answer: TTL_INLINE is pointless. It is used only on declarations of member functions which are defined ...


5

Use of static in a lambda is okay, but it might not be what you want. If you use static, the variable is persistent over lambda instantiations. If the behaviour you want is instead equivalent to dependency injection, you may consider using the mutable keyword. The following code illustrates the difference: void foo() { auto f = [k=int(1)]() mutable { ...


4

MallocAllocator(const MallocAllocator&) noexcept = default; //... ~MallocAllocator() noexcept = default; These two will be defined implicitly anyway. I suggest following the rule-of-zero and not declaring them at all. It will not make a difference here, but as general rule this is relevant, because e.g. the declared destructor inhibits declaration of ...


4

I'm still getting used to Boost::Process, so maybe I've got this wrong. However, do you really need the c.wait() after ios.run()? As per their documentation, control will be blocked at ios.run() until io_context is finished or of-course if your deadline_timer expires.


8

Use std::size_t for container sizes and indices, not int. std::size_t queueFront; std::size_t queueRear; std::size_t maxSize; Use meaningful variable names. When I use your constructor, what does "x" mean? Something like queue_size is more meaningful. This can also be a std::size_t. This also doesn't need to be a reference, since it's likely the same size ...


Top 50 recent answers are included