Hariyana Grande
oh i see
Hariyana Grande
thank you so much
Oleg
os give you the number but convert it into ascii character
Oleg
god, I swear I'm wrong somewhere, I feel it. Correct me, if I'm mistaken.
Hariyana Grande
now it makes sense thanks
Hariyana Grande
no i dont think so u are correct
Oleg
oh i see
read about arithmetic of pointers in c++.
Hariyana Grande
i mean u r correct lol
Hariyana Grande
sure
сумбула
if i use "using namespace std" does it take extra memory or not?
Nameful
It doesn't affect the compiled code
Nameful
But it's still a bad idea to use it
сумбула
why?
Nameful
why?
I could explain but it's a really well-documented problem. I suggested you search
Andrew
hi, i would like to ask, does the sleep() function causes busy waiting when used inside a thread, i need a function like sleep but that doesnt block the threads
Andrew
while the others keep running
Anonymous
i mean, i only need to block 1 thread
So what's the problem?
Ehsan
i mean, i only need to block 1 thread
sleep() blocks the thread caller not the process caller so don’t worry
Ehsan
use it normally
Andrew
i tought, sleep, is like doing something like while(true), that blocks everything
Ehsan
not the process
Andrew
While true doesn't block everything
i mean if you use while(true) inside a thread, the other threads have to wait, and it consumes cpu power, i could do a sleep function like for(int i = 0 ; i<100000;i++){} to block the thread for a current amount of time, but that would cause busy waiting, so i was wondering if the sleep function uses the same principle but i think no, thanks
Юрій
Anyone help me with crafting udp packet, i need to send udp packet with custom IP source header
Anonymous
i mean if you use while(true) inside a thread, the other threads have to wait, and it consumes cpu power, i could do a sleep function like for(int i = 0 ; i<100000;i++){} to block the thread for a current amount of time, but that would cause busy waiting, so i was wondering if the sleep function uses the same principle but i think no, thanks
no. the sleep function is actually a syscall; a function supported by your operating system. when you call sleep(), the scheduler will move your thread from running state to blocking state, and move it back to ready state once the time you specified has been passed. only once your thread is back to the ready queue, the scheduler can schedule it
Andrew
> the other threads have to wait Why?
sorry i got wrong, i went confused
Andrew
> the other threads have to wait Why?
i meant this https://pastebin.pl/view/d67f54f7 , the output usually is not uniform but a thread occupies it
Andrew
I can see both: thread 1 and thread 2 in the output
yes, but was expecting something like Thread1 Thread2 Thread1 Thread1, or to be generally uniform
Andrew
depends on the scheduler (your os)
thanks, i have things more clear now
Ammar
yes, but was expecting something like Thread1 Thread2 Thread1 Thread1, or to be generally uniform
They both are printing output to stdout. But it won't fair in order Thread1, Thread2, Thread1... You need to use semaphore for that.
Anonymous
They both are printing output to stdout. But it won't fair in order Thread1, Thread2, Thread1... You need to use semaphore for that.
not necessarily a semaphore. there are other synchronization methods that he can use in this case
Anonymous
since he wants 1 per 1, maybe a condition will be better
Ammar
since he wants 1 per 1, maybe a condition will be better
Yeah an atomic conditional variable should be enough. That looks a binary semaphore to me.
Ammar
PAUSE Improves the performance of spin-wait loops. When executing a “spin-wait loop,” processors will suffer a severe performance penalty when exiting the loop because it detects a possible memory order violation. The PAUSE instruction provides a hint to the processor that the code sequence is a spin-wait loop. The processor uses this hint to avoid the memory order violation in most situations, which greatly improves processor performance. For this reason, it is recommended that a PAUSE instruction be placed in all spin-wait loops. An additional function of the PAUSE instruction is to reduce the power consumed by a processor while executing a spin loop. A processor can execute a spin-wait loop extremely quickly, causing the processor to consume a lot of power while it waits for the resource it is spinning on to become available. Inserting a pause instruction in a spin-wait loop greatly reduces the processor’s power consumption. This instruction was introduced in the Pentium 4 processors, but is backward compatible with all IA-32 processors. In earlier IA-32 processors, the PAUSE instruction operates like a NOP instruction. The Pentium 4 and Intel Xeon processors implement the PAUSE instruction as a delay. The delay is finite and can be zero for some processors. This instruction does not change the architectural state of the processor (that is, it performs essentially a delaying no-op operation).
Ammar
https://godbolt.org/z/z8ceGP7v5
Ammar
Another thing is that, use pthread_cond_wait. It will make your program sleep until conditional variable is satisfied and signaled. But because your program sleeps, you may get greater latency (it is better than spinning if your threads are expected to have many contentions).
Pavel
Is it C/C++ question?
Anonymous
Calculate the student's GPA for the semester using C++ program. The program should be able to accept a student's name, matriculation number and number of course he/she is taking for that semester. Then for each course the following data is needed. • The course number a string eg. EEE311 •course credit "an integer" •grade received for the course "a character" Please help me
AishaNath
👍
archi
hey guys anyone knows how to do while loop that it will end if the user enter zero?
archi
int count =0; do { int num; Console.Write("Enter a number: "); num=Convert.ToInt32(Console.ReadLine()); count++; }while (event!=0); what is my mistake with this bro?
ɴꙩᴍᴀᴅ
event is a placeholder. You should evaluate 'num' as it's the user input and what you want to use to make the 0 = exit condition
Anonymous
Print the value 333.546372 in a field width of 15 characters with precisions of 1,2,3,4 and 5.
Anonymous
Print the value 333.546372 in a field width of 15 characters with precisions of 1,2,3,4 and 5.
#include<stdio.h> void main() {//Question 2 B.i float a=123.4567; printf("%.2f\n",a); //Question 2 B.ii float b=3.14159; printf("%.3f\n",b); //Question 3 B.iii printf("%-15.1f\n",333.546372); printf("%-15.2f\n",333.546372); printf("%-15.3f\n",333.546372); printf("%-15.4f\n",333.546372); printf("%-15.5f\n",333.546372); } Return 0;
Pavel
Anonymous
offtop?
It is not C++
Roxifλsz 🇱🇹
offtop?
Looks like C#
Pavel
Ah, shi.. right, didn't notice it
archi
it C# hope you guys dont mind me asking about it bro Im very new to programing
Anonymous
What the fuck is that
Anonymous
Before diving into some complex stuff, learn basic syntax
Ehsan
what do you want the lambda to do
Pavel
auto lambdaSunstract = [](double a, double b) { return a - b; }; double c = lambdaSunstract(10.0, 5.0);
Ehsan
std::function<double(double, double> sub = [](double a, double b){ return b - a}
Ehsan
this is the simple syntax
Pavel
std::function<double(double, double> sub = [](double a, double b){ return b - a}
You don't have to assign it to std::function by the way, you can keep it as lambda type with auto
Ehsan
just showing him the syntax.