314 karma · joined March 2, 2015
Mutex mutexes[SIZE_OF_POOL];
int hash(void* p) { ... }
std::shared_ptr<t> atomic_load( const std::shared_ptr<t>* p )
{
int r = hash(p);
lock(mutextes[r % SIZE_OF_POOL]);
return *p; // Safe copy of p.
}All the other atomic operations (store, etc) use the same lock pool, so it should be fine for the copy! If you want to take a look at gcc's implementation:
https://github.com/gcc-mirror/gcc/blob/bd3f0a53c07086e978ea4...
https://github.com/gcc-mirror/gcc/blob/bd3f0a53c07086e978ea4...
It uses Clang for C/C++/Objective-C/Objective-C++ and exposes itself as a server usable from vim, emacs, sublime ...
Note that the a hype train is a two-edged sword, it will both bring a strong community and might also induce a cliff with the other communities (praising a single god is never a good thing).
Maybe a better example would be a project that mix different libraries with different to convention for their "to string" methods: obj.toString(), to_string(obj), obj.ToString(), obj.to_string()... Which one would you use if you simply want to ouput your object on std::cout? In that case, a type check would be really handy!
As to guess whether Rust will put down C++ forever and ever, is another hard question. It will be a matter of community and sadly money... For instance, Apple's already got a much better market share with Swift (look at the job trends) simply because it's Apple. Same goes for JavaScript greatly helped by Google (V8) for their interest (a faster JavaScript engine ==> better usage of Google's web services).
https://github.com/phresnel/metatrace
Performance 100%!
OCaml is a really clean language though!
As far as I remember in France if you do a 2 years master's degrees, you have a VISA for 1 year to search for a job. One can even search for part-time jobs during his studies. If you succeed, after 2 years more, you can ask for the French citizenship. But, sadly, it collides with the Chinese policy that rejects double nationalities."
As far as I remember in France if you do a 2 years master's degrees, you have a VISA for 1 year to search for a job. One can even search for part-time jobs during his studies. If you succeed, after 2 years more, you can ask for the French citizenship. But, sadly, it collides with the Chinese policy that rejects double nationalities.
France is clearly lacking of interesting jobs (SII) in IT, expect research maybe. Europe is also far from having a perfect society, but nothing is black or white, just gray.
I was working only few weeks ago in Hong-Kong for the biggest French bank in HFT and had a decent salary as a graduated. Hong-Kong follows the US style. I was asked to move to NY for 1XXk but finally opted for a life in Sweden for many other reasons. Anyway, I did my research about NY. With the 1XXk in NY, you must pay a 3000$ * 12 rent (36k) for a 40m², put 1/3 for a future retirement and in case of a terrible health problem (30k$). When you get children, you must pay everything by your own, like fees for 2 children = 15000$ * 2 (30k$). Plus you work 30% hours more, hence make 30% more per hour. Statistically, Americans are richer, so it must be interesting to move there especially when single. It highly depends on your life style and your expected work-life balance.
Beware not to overuse this trick. In the past many other European countries were accessible for virtually free. Until an army of Chineses came, studied for free for 5 years and went back to their hometown without any contribution to the society (taxes, intellectual contributions...). That's why Sweden granted recently the free access to only Europe citizens that anyway pay common taxes in their own country.
- For instance, the reuse of the original variable could be deduced by the compiler. - The bound checking for std::vector can effectively be enable. One could imagine an std::strict_vector that do so.
What I am wondering is: does the same idiomatic memory management applied to C++ would require some huge tweaks to the language, some bad tricks, new keywords, or can it be done without changing its design but enforcing some rules?
I, for instance, have no clues how to deal with your "one unique_ptr two threads" problem. Could it be done in an elegant way in C++?
For the security topic, most of the power of Rust come from a strong typing, safety checks (boundaries), ownership checks... Well, a lot of checks at compile time.
As far as I know of Rust by glancing at the doc frequently, C++11/14 also contains these "safe tools": ownership can be dealt with smart pointers (unique, shared), value semantics, move semantics (rvalues) and the rest. Boundaries checks with the correct containers (std::vector, std::array...). Mutability with "const". Atomicity with std::atomic... Type safety by using explicit conversions, templates instead of macros, variadic args...
Heck, all the drama from C++ seems to come from a misusage or some legacy parts from another age (up to C). In order to avoid people to shot themselves in their feets, why couldn't we just introduce a strict compilation mode a la JavaScript to let say Clang: # pragma strict
# pragma unsafe # pragma safe
Nowadays, good C++11 compilers can even deal with such a things like constexpr. This seems a reachable goal.
What are the true drawbacks of a fully modern C++ code compared to a Rust? Is there any true feature that can't be done in C++ due to a deep problem of conception? Don't le me wrong, I do not seek to diminished the amazing work of Mozilla. I am not talking neither about the other cool features from functional languages, switch cases... that Rust has and C++ don't.