Anonymous
What's the difference between binary_semaphore and counting_semaphore? I look into the std header. The least_max_value is only used in max() which doesn't really do anything. So they are just the same thing?!
If you are going strictly by cppreference documentation, then make sure to go through the whole of it. And if you seek answers maybe you should learn to read standard library code as well. Cppreference mentions the following: LeastMaxValue is the minimum max value, not the actual max value.[...] A counting_semaphore contains an internal counter initialized by the constructor.[...] Going through the code here, confirms the same. I am just pasting snippets relevant to the discussion here. template<ptrdiff_t __least_max_value = __semaphore_impl::_S_max> class counting_semaphore{ static_assert(__least_max_value >= 0); static_assert(__least_max_value <= __semaphore_impl::_S_max); __semaphore_impl _M_sem; public: explicit counting_semaphore(ptrdiff_t __desired) noexcept : _M_sem(__desired) It is __desired which is used and not least_max_val for further decisions as was mentioned in the Cppreference documentation. The _least_max_val is used only in the static assertions so that a compiler error is issued when you pass in a counter value larger than what can be accomodated by the semaphore implementation on that specific platform (this is usually done to ensure lock freeness. If atomic exchange operations and such require a lock on a integer type that is required to fit in the counter value, then this particular implementation does not allow it). Now _M_sem which is of type `semaphore_impl `(an alias for __atomic_semaphore) is defined here : https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/bits/semaphore_base.h#L185 The constructor of this struct is passed in the value of __desired from counting semaphore. This value is then used in all acquire and release operations thereafter.
Richard Luo 🐱
If you are going strictly by cppreference documentation, then make sure to go through the whole of it. And if you seek answers maybe you should learn to read standard library code as well. Cppreference mentions the following: LeastMaxValue is the minimum max value, not the actual max value.[...] A counting_semaphore contains an internal counter initialized by the constructor.[...] Going through the code here, confirms the same. I am just pasting snippets relevant to the discussion here. template<ptrdiff_t __least_max_value = __semaphore_impl::_S_max> class counting_semaphore{ static_assert(__least_max_value >= 0); static_assert(__least_max_value <= __semaphore_impl::_S_max); __semaphore_impl _M_sem; public: explicit counting_semaphore(ptrdiff_t __desired) noexcept : _M_sem(__desired) It is __desired which is used and not least_max_val for further decisions as was mentioned in the Cppreference documentation. The _least_max_val is used only in the static assertions so that a compiler error is issued when you pass in a counter value larger than what can be accomodated by the semaphore implementation on that specific platform (this is usually done to ensure lock freeness. If atomic exchange operations and such require a lock on a integer type that is required to fit in the counter value, then this particular implementation does not allow it). Now _M_sem which is of type `semaphore_impl `(an alias for __atomic_semaphore) is defined here : https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/bits/semaphore_base.h#L185 The constructor of this struct is passed in the value of __desired from counting semaphore. This value is then used in all acquire and release operations thereafter.
Thx very much for very detailed answer
Anonymous
Thx very much for very detailed answer
Btw, a binary semaphore is a counting semaphore instantiated with least_max_val as 1.
Anonymous
I'm a beginner. So can someone suggest me which language should I learn..?
Anonymous
I'm a beginner. So can someone suggest me which language should I learn..?
https://roadmap.sh/ Choose a stack that you are interested in. Pick a language then. Follow the roadmaps. And once you have picked a language that is not C/C++, leave this group and join the group specific to that language to get further guidance
Anonymous
what's your goal?
Good programmer
Anonymous
i use c++ connect ssh but the libssh2 so big and cant static cmake
Anonymous
i want delete the libssh2
Anonymous
but if i dont use libssh2 , how connect remote ssh
Otoniel
Good programmer
You got to be kind of specific, like game developer, system administrator, mobile apps developer, web developer...
Otoniel
Any of those should be good at programming tho
klimi
Good programmer
then learn algorithms, computability, problem solving, data structures and such
Arvin
Web development
Javascript maybe
Anonymous
i use c++ connect ssh but the libssh2 so big and cant static cmake
Why don't you link it dynamically? And this is the first time I am hearing that static linking is failing because of the size of a library.
Otoniel
Web development
Someone sent the roadmap.sh link which is a really good starting point for that
Anonymous
so i need static make code
Anonymous
but libssh2 cant static
صغير
then learn algorithms, computability, problem solving, data structures and such
Same list applies for someone wanting to get into app development as well?
Anonymous
c++ how connect ssh , and need static make how, help
Anonymous
libssh2 cant static
klimi
Same list applies for someone wanting to get into app development as well?
app development for what? if android then add java and kotlin, and no need to go into such depths
Anonymous
diesel@diesel-virtual-machine:~/code/seo_pg/c/ssh2/build$ make [ 33%] Building CXX object CMakeFiles/ssh2proj.dir/ssh2.cpp.o [ 66%] Building CXX object CMakeFiles/ssh2proj.dir/RedisTools.cpp.o [100%] Linking CXX executable ssh2proj /usr/bin/ld: attempted static link of dynamic object `/usr/local/lib/libssh2.so.1' collect2: error: ld returned 1 exit status make[2]: *** [CMakeFiles/ssh2proj.dir/build.make:115: ssh2proj] Error 1 make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/ssh2proj.dir/all] Error 2 make: *** [Makefile:91: all] Error 2
Anonymous
help
klimi
App development for ios, i would have to use xcode correct
i guess, then learn tools for that so you can create applications...
صغير
a friend of mine who is studying told me a good language to learn is ruby because its a type of collector or i can’t remember what the ohrase was
Dm
Not sure I see the relevance here.
It's a way to separate valid code and just messages why not
klimi
a friend of mine who is studying told me a good language to learn is ruby because its a type of collector or i can’t remember what the ohrase was
I don't think ruby has much value in this future... I am not saying it's not good to learn languages for what they are, but if it is your only goal it doesn't feel justified
Anonymous
/usr/bin/ld: /home/diesel/soft/libssh2-1.10.0/src/mac.c:119: undefined reference to `HMAC_Update' /usr/bin/ld: /home/diesel/soft/libssh2-1.10.0/src/mac.c:120: undefined reference to `HMAC_Update' /usr/bin/ld: /home/diesel/soft/libssh2-1.10.0/src/mac.c:124: undefined reference to `HMAC_Final' /usr/bin/ld: /home/diesel/soft/libssh2-1.10.0/src/mac.c:125: undefined reference to `HMAC_CTX_free' /usr/bin/ld: /home/diesel/soft/libssh2-1.10.0/src/mac.c:122: undefined reference to `HMAC_Update' /usr/bin/ld: /usr/local/lib/libssh2.a(mac.o): in function `mac_method_hmac_sha2_256_hash': /home/diesel/soft/libssh2-1.10.0/src/mac.c:162: undefined reference to `HMAC_CTX_new' /usr/bin/ld: /home/diesel/soft/libssh2-1.10.0/src/mac.c:163: undefined reference to `EVP_sha256' /usr/bin/ld: /home/diesel/soft/libssh2-1.10.0/src/mac.c:163: undefined reference to `HMAC_Init_ex' /usr/bin/ld: /home/diesel/soft/libssh2-1.10.0/src/mac.c:164: undefined reference to `HMAC_Update' /usr/bin/ld: /home/diesel/soft/libssh2-1.10.0/src/mac.c:165: undefined reference to `HMAC_Update' /usr/bin/ld: /home/diesel/soft/libssh2-1.10.0/src/mac.c:169: undefined reference to `HMAC_Final' /usr/bin/ld: /home/diesel/soft/libssh2-1.10.0/src/mac.c:170: undefined reference to `HMAC_CTX_free' /usr/bin/ld: /home/diesel/soft/libssh2-1.10.0/src/mac.c:167: undefined reference to `HMAC_Update' /usr/bin/ld: /usr/local/lib/libssh2.a(comp.o): in function `comp_method_zlib_dtor': /home/diesel/soft/libssh2-1.10.0/src/comp.c:324: undefined reference to `inflateEnd' /usr/bin/ld: /home/diesel/soft/libssh2-1.10.0/src/comp.c:322: undefined reference to `deflateEnd' /usr/bin/ld: /usr/local/lib/libssh2.a(comp.o): in function `comp_method_zlib_decomp': /home/diesel/soft/libssh2-1.10.0/src/comp.c:264: undefined reference to `inflate' /usr/bin/ld: /usr/local/lib/libssh2.a(comp.o): in function `comp_method_zlib_comp': /home/diesel/soft/libssh2-1.10.0/src/comp.c:200: undefined reference to `deflate' /usr/bin/ld: /usr/local/lib/libssh2.a(comp.o): in function `comp_method_zlib_init': /home/diesel/soft/libssh2-1.10.0/src/comp.c:161: undefined reference to `inflateInit_' /usr/bin/ld: /home/diesel/soft/libssh2-1.10.0/src/comp.c:157: undefined reference to `deflateInit_' collect2: error: ld returned 1 exit status make[2]: *** [CMakeFiles/ssh2proj.dir/build.make:115: ssh2proj] Error 1 make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/ssh2proj.dir/all] Error 2 make: *** [Makefile:91: all] Error 2
Anonymous
i get this error
Anonymous
when i change . a target_link_libraries(ssh2proj /usr/local/lib/libssh2.a)
Jose
Anonymous
when i change . a target_link_libraries(ssh2proj /usr/local/lib/libssh2.a)
Follow the advice given in the syackoverflow link I suggested. You will have to build libssh from source first
Anonymous
you need, also, the .h (the development symbols)
It is a linker error. Not a compiler error. So not sure why you think it is a missing .h problem
Anonymous
ok i try
Ammar
It's a way to separate valid code and just messages why not
Just because the code in the message doesn't compile, it doesn't mean it's bad code. You're in a discussion, not in a git tree. People don't always need to send full code in a discussion. Not sure I get the point here.
Anonymous
Just because the code in the message doesn't compile, it doesn't mean it's bad code. You're in a discussion, not in a git tree. People don't always need to send full code in a discussion. Not sure I get the point here.
I agree. The bot can definitely be improved. Since a majority of admins agree on its usefulness, the least we can do is to take suggestions from other members on how to improve it and pass it on to the developer of the bot
Jose
It is a linker error. Not a compiler error. So not sure why you think it is a missing .h problem
undefined reference will be 2 things: - The .h file is not used (neither exist nor included). For example, when you use extern in one file, but there isn't a non-extern copy in another .h - The linker doesn't have the .o with the implementation (for example, the .o tells you your code will be in a .so file, or in the same .o file)
Dm
or another way: paste big messages to pastebin not just file
Anonymous
undefined reference will be 2 things: - The .h file is not used (neither exist nor included). For example, when you use extern in one file, but there isn't a non-extern copy in another .h - The linker doesn't have the .o with the implementation (for example, the .o tells you your code will be in a .so file, or in the same .o file)
Please check the libssh code. The header files don't use extern and declare the HMAC* symbols directly. The problem in his case is that libssh requires more work on part of the users to statically link it. Dynamic linking is what is preferred And I am not entirely sure why header files would use extern declarations.
Aman😒
What is difference in int_fast32_ and int
Dm
What is difference in int_fast32_ and int
https://stackoverflow.com/questions/8500677/what-is-uint-fast32-t-and-why-should-it-be-used-instead-of-the-regular-int-and-u
Marco
Hi everybody. I made a small program that use this line of code for random numbers. std::uniform_int_distribution<> dist(0, n - 1); unsigned seed = std::chrono::system_clock::now().time_since_epoch().count(); std::default_random_engine gen(seed); int random = dist(gen); in c++ on my Windows pc. But when i execute It on a Linux virtual machine...It s not random as on my Windows pc. Have u ever had this problem? Is there another nice generator? Maybe the seed Is the problem. Thanks in advance
Chat Boss
Kriss Ny sent a code, it has been re-uploaded as a file
Kriss
Kriss Ny sent a code, it has been re-uploaded as a file
I am trying to implement a stack using a array, I want the program to return the value being popped when pop function is called
Kriss
I am trying to implement a stack using a array, I want the program to return the value being popped when pop function is called
but I think the value are not being pushed in the first place , as it gives me -1 for every pop, even if i push some values
Sandy
Okay
Anonymous
Hi everybody. I made a small program that use this line of code for random numbers. std::uniform_int_distribution<> dist(0, n - 1); unsigned seed = std::chrono::system_clock::now().time_since_epoch().count(); std::default_random_engine gen(seed); int random = dist(gen); in c++ on my Windows pc. But when i execute It on a Linux virtual machine...It s not random as on my Windows pc. Have u ever had this problem? Is there another nice generator? Maybe the seed Is the problem. Thanks in advance
What do you mean it is not random? How did you figure that out? You are choosing a uniform distribution which means all numbers between 0 and n-1 are equally likely. So in a long run of this generator, you will get approximately equal number of random values for each value in the range. And the problem is not the seed. The seed if it is randomly chosen (it being current time in your case) ensures that different runs generate a different sequence of random values. But for an individual run, the values generated must be random according to the distribution you choose irrespective of whether you chose a good seed or not.
Anonymous
what I am doing wrong?
We can't say for sure without seeing what the sequence of your action values are.
Aysel
/start@MissRose_bot
Anonymous
Hi!
Anonymous
I can use this only for scalar type? X some_shit(vector<X>& x_){ vector<X> x; x.reserve(x_.size()); }
Anonymous
I mean reserve method
Anonymous
Everyone, how do I register an input device event in C++, such as when a specific key on the keyboard is pressed or when a mouse button is clicked?
hello, I am doing flutter linux. I use visual studio code as my code editor.
I got g_autoptr with red squiggles from this line in my_application.cc g_autoptr(FlDartProject) project = fl_dart_project_new(); I see that in gmacros.h it is defined but greyed out. Why is that and how to enable that macro in my project? I come from Swift and Dart so you can expect me with little knowledge about C/C++. Thank you!
Fonzi
hi im new to C++ const char * foo = "example"; const char* foo2 = foo is there a way to convert or cast const char* foo2 variable to utf8 without changing to prefix u8"example"
Kriss
We can't say for sure without seeing what the sequence of your action values are.
I got 😅, I created my stack inside the loop,so it was made and being destroyed for every testcase
Mahmoud
C++
Mahmoud
Best language in the world
itsmanjeet
Hey everyone, I need help in template constructor specialization, checked the internet for hint but none work as expected. I have a class Value and need 3 constructor to be with Value(AnyIntegerType), Value(AnyFloatingType), and Value(AnyOtherType) for Integer template <typename T, std::enable_if<std::is_integral<T>::value>* = nullptr> Value(T val) for FloatingPoint template <typename T, std::enable_if<std::is_floating_point<T>::value>* = nullptr> template <typename T, std::enable_if<!std::is_floating_point<T>::value && !std::is_floating_point<T>::value>* = nullptr> Value(T val) Value(T val)
itsmanjeet
But getting more than one constructor applies to convert from "int" to "Value" for Value(34)