So I'm pretty confused when to use std::thread or prthreads. It seems they both have the same methods/classes e.g. both have mutexes, condition variables etc.
I'm developing on Windows and using Mingw. std::thread isn't implemented on it yet but someone implemented it here github.com/meganz/mingw-std-threads but if I'm going to be using third party libraries anyways then doesn't that defeat the purpose of using std::thread?
If I'm going to be using third party libraries anyway then is there a better one to use?
@northerner No, not really. Your code is following the standard, so the third party library is purely a temporary measure to make up for the shortcoming(s) of a particular implementation at a particular time.
@northerner Not to me knowledge--at least not right now.
@JerryCoffin I still don't see that argument. The methods are the same for pthread so wouldn't it be just as easy to switch from pthread to std::thread as some github library to std::thread
it is said that one should always use uint8_t or int8_t when doing calculations with data that is 1 byte. And when somehow dealing with text it is better to use char instead. But in this case why do we differentiate signed and unsigned char? You ar not supposed to care as this is not for calculations
When I released the previous version of my library I had 1 bug reported (stilll not fixed), and while working on the next version I found 10 more bugs and not even in new code x)
@traducerad it's never mattered for me. In theory you can use it on systems you know are 8bit char to detect unicode or double byte
@traducerad my point was more that fixed width ints shouldn't be used just randomly, they can have very significant and negative impacts if you're not careful. Most RISC platforms for example don't really support anything greater or smaller than native word size without a lot of extra instructions.
@traducerad final semi-random point... in theory you should use the type corresponding to the character set you're using... hence the introduction of char8_t in c++20
@Mgetz are you saying that whenever you are writing software on a new piece of hardware you always check the generated assembly code to understand the impact? Even when writing in a highlevel language like cpp?
Don't you end up spending more time reading asm than writing cpp if that's the case? The asm code varies quite a lot from hardware to hardware and is imo not always very easy to understand
Thing is, every project i have worked on so far used fixed width ints. At some point or another you will want to send that data to some other device using a given protocol. Having fixed width ints guarantees the communication /protocol won't be impacted if you eg migrate your software to new hardware whose "native" datatype differs. Time is money. As long as you meet the performance requirements linked to your product /project i think you d better stick with fixed width for portability
for instance, I seem to recall that there are some older APIs that couldn't be used from some compilers, as they name mangled it based on the type, and they had different widths in different implementations
@Mgetz ISTR that GCC has an option for it and MSVC always allows it because they tried disabling it and it turned out they have 1mloc of code that relies on it or something like that
the default int is fine until you realise that you totally fucked up and it actually did matter, but now it's too late to fix it and you weren't in the hot path anyway and had a problem for nothing
I meant that in a cleaner version of the Standard, there only really needs to be int and unsigned int in 8, 16, 32, 64 (maybe 128) and sizeof(void*)
not that they're defined as the same in the current standard
@Mgetz But by the time you figure out if it does apply, it's often too late, so it's often wise to optimise up front.. (also the default can be and often is wrong)
@Puppy so in some places (interfaces because of ABI, serialization, security sensitive code) it makes 100% sense. But in places those don't apply, it's an overoptimization.
cause people never, ever make mistakes in applying those rules, no sir, and when they do make those mistakes, they sure don't last for years or decades
there's a difference between an optimisation and making sure you don't run into critical maintainability problems
my position has nothing to do with performance of any kind
I know the pain, and using variable width increases the pain since your integers randomly change size instead of being how you originally wanted them to be
@traducerad irony.. I'm for the opposite reason, because I've seen people assume widths and gotten burned on it whereas if they had just used the right types in the first place it would have been fine. I know that sounds like I should favor fixed width... but they were over engineering.