Forum Replies Created
-
AuthorPosts
-
::
The clang-tidy rule modernize-pass-by-value suggests to replace the use of const references constructor parameters that are copied into class fields with a pass by value that is then moved.
::Thank you all for your posts! Very interesting.
I work on the timing model of FPGAs. An FPGA is a device that has an undefined function at the time of manufacture, it is programmed on the field. A large component of the product is the software that is used to program the device and verify that it will function as expected. Part of that verification is making sure that data can be reliably transferred from register to register in the FPGA and between registers on the FPGA and other devices on the board, that’s where the timing model for the device comes in.
I am responsible for part of the data that is consumed by the timing model and I am currently restructuring how we store, verify and query package parasitics and I am adding new functionality to support new packaging methodologies.
::Thanks Driton! Yes this is one instance where I thought this could happen.
The part that I was missing is that this doesn’t result in a deadlock because as you say condVar1 releases the mutex, goes to sleep and waits for the notification. I agree one thread could acquire the lock at most twice in a row since the second time around the wait call fails and the thread is blocked until the other thread returns the ball.
It could happen multiple times I think, just each time at most twice in a row, for instance if for some reason the call to lock in the last row of the table below (vertical axis is time) gets delayed and t1 has a chance to acquire the lock again before t2 gets a chance to do so. Ultimately the ping pong functionality remains the same with the two threads taking turns in changing the value of the variable.
t2(set_false) t1(set_true) lock wait success set variable to true notify lock wait fail unlock lock wait success set variable to false notify wait success lock set variable to true lock ::Thanks Rainer. I thought overflow only got called when the sink is exhausted like in the example in the page for std::streambuf::overflow.
But I see from your comment that in this case overflow gets called in each of the lines log << … in main
I see in cppreference here that the description of std::streambuf::overflow is that it writes characters to the associated output sequence from the put area, so this is in line with your example. In the example in the std::streambuf::overflow page, why does overflow only get called when we exhaust the space in the array that is being used as the sink?
::Does not generalizable mean compiler-dependent and/or architecture-dependent?
I was asking the question about size because SL.Con.2 says: “Even when other containers seem more suited, such as map for O(log N) lookup performance or a list for efficient insertion in the middle, a vector will usually still perform better for containers up to a few KB in size.”
So I guess the few KB in size is referring to the size of the vector, which we can determine.
::For the advantage about the contiguous layout I see now that the section “Memory predictability” in the modernes post has an experiment that elaborates on what cache-friendly means.
::In the example above, why do we care about external linkage if we are using the is_arithmetic_v template variable in the same source file?
Could you elaborate under which circumstances the absence of inline would result in undefined behavior?
My understanding is that:
- inline means that we allow multiple definitions
- for an inline variable or inline function, a definition is required in every translation unit that uses it (from Bob Steagall’s The structure of a program in Back to Basics)
In the example above, if we wanted to use is_arithmetic_v in two .cpp files couldn’t we just define is_arithmetic_v in a header file as:
constexpr bool is_arithmetic_v = is_arithmetic<T>::value;
and include the header file in the two .cpp files?
It is not clear to me what is the value of the keyword inline. So there must be something I am not understanding :)
::And indeed I saw my post above right away, no pending moderation message. I posted the message above and this message from an incognito window where I logged in to modernes. I wonder if somehow in my other window where I posted the has function topic I was not logged in but still looked as if I was logged in. I could see all the lessons, the resources page and the forum.
::On the slide about constexpr member functions, it says that they can only be executed by constexpr instances but the code below compiles. Is this a typo on the slide or am I misunderstanding something? The compiler does complain about the instance being non-constexpr if I declare result to be constexpr.
#include <iostream> class MyClass{ public: constexpr double interest(double k) const { return k * amount; } void show() const { std::cout << amount << std::endl; } private: int amount{20}; }; int main(){ MyClass nonConstInstance; double result = nonConstInstance.interest(0.10); nonConstInstance.show(); };
-
AuthorPosts