![]() |
[QUOTE=Dubslow;299561]Hey LaurV/anybody else, I got another mismatch (still using 2.00). Could you run [URL="http://mersenne.org/report_exponent/?exp_lo=25831787"]M25831787[/URL] and tell me when you submit the result?[/QUOTE]
I'm running it now, I'll let you know. |
[QUOTE=Dubslow;299561]Hey LaurV...[/QUOTE]
Sorry, I am temporary out of the game, half of the resources are totally busy, and the other half are split down to pieces and spread through all the house, fact that is maximum pissing off Mrs LaurV... ([URL="http://www.mersenneforum.org/showpost.php?p=297948&postcount=888"]switching [/URL]to liquid cooling). |
Could someone help me understand what this code does?
[code]int _kbhit (void) { struct termios oldt, newt; int ch; int oldf; tcgetattr (STDIN_FILENO, &oldt); newt = oldt; newt.c_lflag &= ~(ICANON | ECHO); tcsetattr (STDIN_FILENO, TCSANOW, &newt); oldf = fcntl (STDIN_FILENO, F_GETFL, 0); fcntl (STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK); ch = getchar (); tcsetattr (STDIN_FILENO, TCSANOW, &oldt); fcntl (STDIN_FILENO, F_SETFL, oldf); if (ch != EOF) { ungetc (ch, stdin); return 1; } return 0; }[/code] |
Looks like it checks if a key was pressed, and if so, put it back in the queue but signal the caller that a character can now be retrieved.
P.S. A copy of the normal term i/o handler is created except it is now non-blocking. If you ask for a char from normal code, it will sit doing nothing _until_ you press the key. Here, this routine will report to the caller - "there was no activity, carry on". |
[QUOTE=Batalov;299660]Looks like it checks if a key was pressed, and if so, put it back in the queue but signal the caller that a character can now be retrieved.[/QUOTE]Hmm... that's what the last few lines looked like, but I've never run across termios before... to that end, I'm going through [URL="http://blog.nelhage.com/2009/12/a-brief-introduction-to-termios/"]this[/URL] and its follow-ups; why not just do something like[code]char c = getchar(); if(c!=EOF) { ungetc(c, stdin); return 1;} else return 0;[/code] ...? In other words, what's the point of the termios stuff? I'll try and figure it out on my own, but I'm leaving soon for a couple of hours.
|
[QUOTE=Dubslow;299661] why not just do something like[code]char c = getchar(); if(c!=EOF) { ungetc(c, stdin); return 1;} else return 0;[/code] ...?[/QUOTE]
Because in that case (your code) the computer is locked until you decide to press the dammit key. The monkey bar joke. When I was child I did a lot of quarters with "I bet you a quarter you can't hang on it until I count to 10". Many of my friends took the bet, then I was counting very fast to 9, and going away living them hanging on the bar. Eventually they felt down and lost the bet, because they could not hold on it [U]until[/U] I counted to [U]10[/U]. The original code does a lot of work to modify the behavior of the getchar() routine to return immediately in case no key was already pressed, without waiting for the key, and if a key was pressed, to get its [U]scan code[/U], (accepting key combinations, like CTRL+ALT+F12), and terminate if ctrl+c was pressed. After the key is read, the old behavior (waiting for the key) is restored. Se for details [URL="http://www.daniweb.com/software-development/c/threads/147540/how-can-we-get-scan-code-in-c-using-gcc-compiler"]here[/URL] and [URL="http://www.daniweb.com/software-development/cpp/threads/331393/to-generate-keystrokes-using-c-linux-os"]here[/URL] (follow the fork link in that post). |
[QUOTE=LaurV;299670]Because in that case (your code) the computer is locked until you decide to press the dammit key. The monkey bar joke. When I was child I did a lot of quarters with "I bet you a quarter you can't hang on it until I count to 10". Many of my friends took the bet, then I was counting very fast to 9, and going away living them hanging on the bar. Eventually they felt down and lost the bet, because they could not hold on it [U]until[/U] I counted to [U]10[/U].
The original code does a lot of work to modify the behavior of the getchar() routine to return immediately in case no key was already pressed, without waiting for the key, and if a key was pressed, to get its [U]scan code[/U], (accepting key combinations, like CTRL+ALT+F12), and terminate if ctrl+c was pressed. After the key is read, the old behavior (waiting for the key) is restored. Se for details [URL="http://www.daniweb.com/software-development/c/threads/147540/how-can-we-get-scan-code-in-c-using-gcc-compiler"]here[/URL] and [URL="http://www.daniweb.com/software-development/cpp/threads/331393/to-generate-keystrokes-using-c-linux-os"]here[/URL] (follow the fork link in that post).[/QUOTE] Sweet! I knew there was a stupidly easy and obvious explanation :smile: I swear I'm not usually this dumb :razz: Edit: It seems to be formulaic enough that I can reuse it without a problem; it seems that actually understanding it will require quite a bit of time reading through 'man termios', which I'll do later. Thanks for the help, B&L. |
[QUOTE=Dubslow;299561]Hey LaurV/anybody else, I got another mismatch (still using 2.00). Could you run [URL="http://mersenne.org/report_exponent/?exp_lo=25831787"]M25831787[/URL] and tell me when you submit the result?[/QUOTE]
Original is correct. You want me to post the DC to PrimeNet? |
{sarcasm}
No, clearly, to make things right you should pass the residue to Dubslow, so that he could submit it as a CUDALucas residue. After all, the error was now corrected! {/sarcasm} Seriously, if you don't want people to make suggestions like the above you could PM each other. OTOH, if you value other people's opinions, you should simply let the server do its job of tallying correct and incorrect residues and enforce impartiality by assigning the double-check to a [B]random[/B] [strike]person[/strike] computer that is not going to have an preconceived agenda if it is right, or even "polite" to correct someone else's mistake ("What if I hurt his feelings by pointing out that his residue was incorrect? Ah, ah, ah, what should I do?!"). Dudes, grow up already - these are just numbers! You voluntarily turn yourselves into [URL="http://en.wikipedia.org/wiki/Human_computer"]human computers[/URL]. |
[QUOTE=Batalov;299740]{sarcasm}
No, clearly, to make things right you should pass the residue to Dubslow, so that he could submit it as a CUDALucas residue. After all, the error was now corrected! {/sarcasm} Seriously, if you don't want people to make suggestions like the above you could PM each other. OTOH, if you value other people's opinions, you should simply let the server do its job of tallying correct and incorrect residues and enforce impartiality by assigning the double-check to a [B]random[/B] [strike]person[/strike] computer that is not going to have an preconceived agenda if it is right, or even "polite" to correct someone else's mistake ("What if I hurt his feelings by pointing out that his residue was incorrect? Ah, ah, ah, what should I do?!"). Dudes, grow up already - these are just numbers! You voluntarily turn yourselves into [URL="http://en.wikipedia.org/wiki/Human_computer"]human computers[/URL].[/QUOTE] No problem either way... He asked someone to run a TC, and I did. I had no intention good or bad, I just want to know if he wants me to submit to PrimeNet or if he wants to run it again. I'm not sure where you perceieved a problem, but there is none. |
Submit the successful triple-check first.
If you submit the bad double-check first, then there is a window where the server will make the exponent available to some poor unsuspecting user for a triple-check. |
| All times are UTC. The time now is 23:15. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.