Qt/QML application crashes at start-up in Debug Mode - c++
I'm using Qt 5.3 mingw on windows and writing application with Qt/QML.
sometimes, a crash happens at start-up when I run the project in Debug mode and trying to debug the code.
the inferior stopped because it received a signal from operating system
Is there any problem with QML or something else?
the stack is like this when error happens.
0 QScopedPointer<QObjectData, QScopedPointerDeleter<QObjectData> >::data 143 0x9d2250c
1 qGetPtrHelper<QScopedPointer<QObjectData> > 941 0x99e1cc7
2 QOpenGLContext::d_func 148 0x9d21f9b
3 QOpenGLContext::isValid 596 0x99e05d1
4 GLAcquireContext::GLAcquireContext 75 0x1af7ec21
5 QQuickContext2DTexture::paint 247 0x1aef2b79
6 QQuickContext2DTexture::event 366 0x1aef34a1
7 QApplicationPrivate::notify_helper 3500 0x217eded3
8 QApplication::notify 2953 0x217eb985
9 QCoreApplication::notifyInternal 935 0x6b929f96
10 QCoreApplication::sendEvent 237 0x6b9cf2db
11 QCoreApplicationPrivate::sendPostedEvents 1539 0x6b92b14e
12 QEventDispatcherWin32::sendPostedEvents 1143 0x6b97b006
13 qt_internal_proc(HWND__*, unsigned int, unsigned int, long)#16 421 0x6b978708
14 gapfnScSendMessage C:\Windows\syswow64\user32.dll 0x768362fa
15 ?? 0x2e07d2
16 USER32!GetThreadDesktop C:\Windows\syswow64\user32.dll 0x76836d3a
17 __lambda0::operator() 364 0x6b978443
18 ?? 0x2e07d2
19 USER32!CharPrevW C:\Windows\syswow64\user32.dll 0x768377c4
20 USER32!DispatchMessageW C:\Windows\syswow64\user32.dll 0x7683788a
21 QEventDispatcherWin32::processEvents 756 0x6b979a0b
22 QEventLoop::processEvents 136 0x6b92803c
23 QEventLoop::exec 212 0x6b9282d7
24 QThread::exec 511 0x6b795f49
25 QThread::run 578 0x6b7960b1
26 QThreadPrivate::start(void*)#4 407 0x6b798b3e
27 msvcrt!_itow_s C:\Windows\syswow64\msvcrt.dll 0x76231287
28 msvcrt!_endthreadex C:\Windows\syswow64\msvcrt.dll 0x76231328
29 KERNEL32!BaseThreadInitThunk C:\Windows\syswow64\kernel32.dll 0x76a233aa
30 ntdll!RtlInitializeExceptionChain C:\Windows\system32\ntdll.dll 0x77079ef2
31 ntdll!RtlInitializeExceptionChain C:\Windows\system32\ntdll.dll 0x77079ec5
32 ??
Any suggestion will be appreciated.
Thanks in advance.
Related
Issue generating DAG using CausalFS cpp package
Link to CausalFS GitHub I'm using v.2.0 of CausalFS cpp package by Kui Yu. Upon running the structural learning algos, my DAG and MB are not matching. I'm trying to generate a DAG based on the data given in the CDD/data/data.txt directory and CDD/data.txt via some of the Local-to-global structure learning algos mentioned in the manual (PCMB-CSL, STMB-CSL etc.). Running the commands as given by the manual (pg. 18 of 26). But my resulting DAG is just filled with zeros (for the most part). Given that this is a example dataset that looks suspicious. Upon then checking CDD/mb/mb.out I find that the Markov blankets for the variables do not agree with the DAG output. For ex, running ./main ./data/data.txt ./data/net.txt 0.01 PCMB-CSL "" "" -1 gives a 1 at position (1,22) (one-indexed) only (relaxing alpha value to 0.1 (kept at 0.01 in ex) gives just another 1). However, this doesn't agree with the output MB for each variable, which looks like (upon running IAMB as ./main ./data/data.txt ./net/net.txt 0.01 IAMB all "" "")- 0 21 1 22 26 28 2 29 3 14 21 4 5 12 5 4 12 6 8 12 7 8 12 8 6 7 12 9 11 15 10 35 11 9 12 15 33 12 4 6 7 8 11 13 13 8 12 14 15 17 30 34 14 3 13 20 15 8 9 11 13 14 17 30 16 15 17 13 15 18 27 30 18 17 19 20 27 19 18 20 20 14 18 21 28 21 0 3 20 26 22 1 21 23 24 28 23 1 22 24 24 5 22 23 25 25 24 26 1 21 22 27 17 18 28 29 28 1 18 21 22 27 29 29 2 27 30 13 14 15 17 31 34 32 15 18 34 33 11 12 32 35 36 34 30 31 32 35 36 35 10 33 34 36 33 34 35 Such an MB profile suggests the DAG to be much more connected. I would love to hear suggestions from people who've managed to get the package to behave appropriately. I just do not understand the error here from my side. (I'm running on PopOS 20.04) Thanks a bunch <3 P.S- The files just continue to write upon rerunning the code, so make sure to appropriately delete them.
Perl regex: More than one line to match and output in a given format: Completely revised
If one can understand how to store stuff in memory, know where it is and how to get it out again in an orderly way it will go a long way to achieving results in Perl.(And probably all programming languages) I am not a programmer. I am trying to extract data from 'older program' output and import it into a SQL database. The extraction is the thing. My previous question was largely incorrect, as I found out when importing data into the table, as I did not have enough data from the 'old program' output file. I would like to learn from my mistake and re-ask my previous question, hopefully correctly this time. I have included my poor effort at extracting the data, exactly as it was last time. It doesn't come anywhere near getting the correct data out. I believe this is quite a complex question but maybe it isn't. It is certainly above my level of Perl at present, and maybe ever. Answers to my incorrectly phrased question have been partially understood. Thank you very much for them. If I could summarize it, my main problem with this task is dealing with the type of question: 'If a line contains ... get data from two lines up and insert it at the beginning of .... Seemingly impossible for me. I tried regex over the end of line searches but was unable to get that to work. I was unable also to arrange successive loops to insert data in lines as I wanted. If one loop worked, the next did not and so on. I was prepared to work on successive files in a step by step process but the 'two lines up' question stumped me completely. I was able to extract other data from these output files relatively easily as they are very orderly files, but this particular question has me stumped. My revised question is: My input file consists of batches of data(+-50 - 70 lines long) in the following format: 1(P1) 3 P.ell 05/0120 W/P068819 0 12.0 98/99 380 380 C03 104 PROCESSED 21/02/16 TIME 22.16.52 KSINA=8 AGE SPH %THN %INC SV SI MAI20 HTPC VIPC AGE BA DBH HT SPH CIH% CIV% CVD BCON CMAI C0 C0CAL SI20 0 1100 .0 89.0%SPH 2 2 .00 .0 .0 20.00 1 .0 17.3 0 .0 .0 .0 .0 .0000 .000 0% .00 7 815 25.9 .0 2 2 9.90 75.5 47.2 20.00 1 26.6 17.3 330 .0 .0 .0 13.0 .2099 1.005 .000 17.30 13 550 32.5 .0 18 330 40.0 .0 45 0 100.0 .0 0SQ -4 -4 -4 = SI20 17 17 17 PLANTN---104 GREEN MEADOWS MODEL---P.ELLIOTTII MAC MAC SQ 10 SI20 22.90 HTPC 76 76 76 =MAI20 10 10 10 FROM HTPC HTPC 100 MAI20 20.71 VIPC 47 47 47 =MAI20 10 10 10 HTPC/VIPC REGRESSION---P.ELLIOTTII GENERAL 1/83 VIPC 100 MAI20 20.99 MAIDBH 0 INMAI==> 0 0INPUT FOR CALCULATING HTPC & VIPC = HT ---- ---- AGE DBH HT VTREE SPH BA TOTAL WS UTIL S A B C D TCAI CTCAI TMAI UCAI CUCAI UMAI SCAI CSCAI SMAI IAGE 1 .0 .2 .0000 979 0 0 0 0 0 0 0 0 0 .0 0 .0 .0 0 .0 .0 0 .0 1.0 2 .0 .9 .0000 979 0 0 0 0 0 0 0 0 0 .0 0 .0 .0 0 .0 .0 0 .0 2.0 3 3.9 2.0 .0007 979 1 1 1 0 0 0 0 0 0 .7 1 .2 .0 0 .0 .0 0 .0 3.0 4 7.1 3.4 .0041 979 4 4 3 1 1 0 0 0 0 3.4 4 1.0 .6 1 .2 .0 0 .0 4.0 5 9.4 4.6 .0102 979 7 10 5 5 5 0 0 0 0 5.9 10 2.0 4.1 5 .9 .0 0 .0 5.0 6 11.3 5.7 .0188 979 10 18 6 12 12 1 0 0 0 8.4 18 3.1 7.5 12 2.0 .0 0 .0 6.0 7 13.0 6.7 .0293 979 13 29 7 22 19 3 0 0 0 10.3 29 4.1 9.7 22 3.1 .0 0 .0 7.0 17% THN 11.4 6.7 .0230 164 2 4 1 3 2 0 0 0 0 REM 13.4 6.7 .0315 815 12 26 6 20 17 3 0 0 0 8 15.0 7.6 .0453 815 14 37 6 31 21 10 0 0 0 11.2 40 5.0 10.9 33 4.1 .0 0 .0 7.6 9 16.4 8.5 .0607 815 17 49 6 43 23 20 0 0 0 12.5 52 5.8 12.2 45 5.0 .2 0 .0 8.6 10 17.4 9.4 .0771 815 19 63 7 56 24 30 2 0 0 13.4 66 6.6 13.1 58 5.8 1.3 2 .2 9.6 11 18.3 10.3 .0941 815 21 77 7 70 24 41 5 0 0 13.9 80 7.3 13.6 72 6.5 3.0 5 .4 10.6 12 19.0 11.3 .1118 815 23 91 7 84 24 50 10 0 0 14.4 94 7.8 14.1 86 7.2 5.4 10 .8 11.6 13 19.6 12.2 .1299 815 25 106 8 98 24 56 18 0 0 14.7 109 8.4 14.4 100 7.7 8.0 18 1.4 12.6 33% THN 17.5 12.2 .1044 265 6 28 2 25 8 15 3 0 0 REM 20.6 12.2 .1421 550 18 78 5 73 16 42 15 0 0 14 21.3 13.0 .1636 550 20 90 6 84 16 44 25 0 0 11.8 121 8.6 11.6 112 8.0 10.0 28 2.0 10.4 15 22.0 13.7 .1864 550 21 103 6 97 16 45 36 0 0 12.5 133 8.9 12.3 124 8.3 11.0 39 2.6 11.2 16 22.7 14.5 .2100 550 22 116 6 109 15 46 48 0 0 13.0 146 9.1 12.7 137 8.6 12.0 51 3.2 12.0 17 23.3 15.3 .2345 550 23 129 6 123 15 46 61 0 0 13.5 160 9.4 13.2 150 8.8 12.9 64 3.8 12.8 18 23.9 15.9 .2598 550 25 143 7 136 15 46 74 1 0 13.9 174 9.6 13.6 164 9.1 13.8 78 4.3 13.6 40% THN 21.6 15.9 .2142 220 8 47 2 45 6 19 20 0 0 REM 25.3 15.9 .2901 330 17 96 4 92 9 28 54 1 0 19 26.0 16.6 .3203 330 17 106 4 101 9 27 63 3 0 10.0 184 9.7 9.8 174 9.1 10.5 88 4.6 11.0 20 26.6 17.3 .3519 330 18 116 5 112 9 27 71 5 0 10.4 194 9.7 10.2 184 9.2 10.6 99 4.9 11.7 21 27.2 18.0 .3849 330 19 127 5 122 9 27 80 8 0 10.9 205 9.8 10.7 194 9.3 11.1 110 5.2 12.4 22 27.9 18.7 .4192 330 20 138 5 133 8 26 87 11 0 11.3 216 9.8 11.1 206 9.3 11.5 121 5.5 13.2 23 28.4 19.3 .4546 330 21 150 5 145 8 26 94 16 0 11.7 228 9.9 11.4 217 9.4 11.8 133 5.8 14.0 24 29.0 20.0 .4914 330 22 162 5 157 8 26 101 22 0 12.2 240 10.0 11.9 229 9.5 12.3 145 6.1 14.9 25 29.6 20.6 .5292 330 23 175 6 169 8 25 106 29 0 12.5 253 10.1 12.2 241 9.6 12.6 158 6.3 15.7 26 30.2 21.2 .5682 330 24 188 6 182 8 25 112 37 0 12.9 265 10.2 12.6 254 9.8 13.0 171 6.6 16.5 27 30.7 21.8 .6083 330 25 201 6 194 8 25 115 46 0 13.2 279 10.3 13.0 267 9.9 13.3 184 6.8 17.3 28 31.3 22.4 .6492 330 25 214 7 208 8 24 119 56 1 13.5 292 10.4 13.2 280 10.0 13.6 198 7.1 18.2 29 31.9 23.0 .6908 330 26 228 7 221 8 24 122 65 2 13.7 306 10.5 13.5 293 10.1 13.8 212 7.3 19.0 30 32.4 23.5 .7332 330 27 242 7 235 8 24 123 77 3 14.0 320 10.7 13.7 307 10.2 14.0 226 7.5 19.8 31 33.0 23.9 .7766 330 28 256 7 249 8 24 125 88 5 14.3 334 10.8 14.0 321 10.4 14.3 240 7.7 20.4 32 33.6 24.4 .8202 330 29 271 8 263 8 23 126 99 7 14.4 349 10.9 14.1 335 10.5 14.4 255 8.0 21.0 Firstly the two variables in the first line(1(P1...): in this case 'C03 104' need to be extracted from it and be sent to OUTPUT.(Same as previous question, but the output position changes.) Secondly, all lines beginning with 'THN' need to be extracted as they are except that the THN can be dropped. If there are two, three, four or even five etc. 'THN' lines, they all need to be extracted from the batch and sent to OUTPUT.(+- same as previous question) Thirdly, although sequentially the second step, the last figure in the 'AGE' column of the main tabular data just before the 'THN' line, needs to be attached to the extracted 'THN' line directly below it.(in this case the figures 7, 13 and 18) These need to be added to their respective THN lines. See expected output below where the ages have been inserted after the two 'C03 104' variables in each line. If there are no 'THN' lines in a given batch, the entire batch should be ignored, with no output, and the next batch(starting with a '1(P1)' again) considered. The correct output expected from the above batch is: CO3 104 7 11.4 6.7 .0230 164 2 4 1 3 2 0 0 0 0 CO3 104 13 17.5 12.2 .1044 265 6 28 2 25 8 15 3 0 0 CO3 104 18 21.6 15.9 .2142 220 8 47 2 45 6 19 20 0 0 As will be seen from this, the two variables from the top line are inserted at the start of the output THN data line. The age figure read from the input batch is then inserted into its respective THN line and thereafter the rest of the THN line data is attached. My effort some time ago but not updated is as follows: while ( my $line = <INPUT> ) { if($line =~ /\s{6,11}(\w{1}\d{1}\w{0,5})\s{0,5}(\d{3})/) { my #c_no = "$1,$2\n"; foreach (#c_no) { print OUTPUT $_; } if ($line =~ /^(\s{1}THN)(\s{1,3}\d{0,2}.\d)(\s{1,3}\d{0,2}.\d)(\s{1,2}\d{0,1}.\d{4})(\s{1,2}\d{2,4}) (\s{2,3}\d{1,2})(\s{1,6}\d{1,4})(\s{1,2}\d{1,2})(\s{1,5}\d{1,4})(\s{1,4}\d{1,4}) (\s{1,4}\d{1,4})(\s{1,4}\d{1,4})(\s{1,4}\d{1,4})(\s{1,4}\d{1,4})|(^1(P1))/x){ print OUTPUT "$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14\n"; } } } Advice, guidance and help would be greatly appreciated.
This is much more simply done using split to separate each line into space-delimited fields, and quite straightforward if you maintain state variables for the two fields from the header row, and the age from any row whose first field is entirely digits. Then all that is necessary is to print these three values before the numbers on any line that starts with THN Note that it's simplest to pass the name of the input file as a parameter on the command line. Then all you have to do is read from <>. All the opening and error handling are already done for you The output format you've asked for is rather esoteric. I can't see any pattern to the column widths and I've had to write a custom printf format to recreate it. If you need something else then all the values in each output line are in the #data array, which you can use as you wish use strict; use warnings 'all'; my ($c1, $c2, $age); while ( <> ) { next unless /\S/; my #fields = split; if ( $fields[0] eq '1(P1)' ) { ($c1, $c2) = #fields[10,11]; } elsif ( $fields[0] !~ /\D/ ) { $age = $fields[0]; } elsif ( $fields[0] eq 'THN' ) { my #data = ( $c1, $c2, $age, #fields[1..13] ); printf "%4s %5s %5d %5.1f%5.1f%7.4f%5d%4d%7d%3d%6d%5d%5d%5d%5d%5d\n", #data; } } output C03 104 7 11.4 6.7 0.0230 164 2 4 1 3 2 0 0 0 0 C03 104 13 17.5 12.2 0.1044 265 6 28 2 25 8 15 3 0 0 C03 104 18 21.6 15.9 0.2142 220 8 47 2 45 6 19 20 0 0
I copied and modified your example data, so this hasn't had a really good test. And I'm printing to STDOUT for testing purposes, but that should be easy to change. The trick is to recognize that you've got line matching to do, which is great with regexes, and other processing, which is probably better with plain old code. So build a little loop, and process the lines with equal precedence (this is important for detecting errors in the file - don't try to nest things too much). Put in some state variables to help keep track of what comes next, and be sure to reset them appropriately. Also, one thing I noticed in your example code is that you spent a lot if time getting spacing and number-of-digits right for the fields. That was almost certainly wasted time in this context, since the key was the "THN" at the start of the line. One trick with processing text is to focus on the things you really need, and use .* for the other stuff. That way, line noise or a syntax error or some strange formatting glitch won't screw up your program. (Sometimes .* becomes [^"]* or whatever, but you take the point...) my $line_prefix, $have_age_col, $age_col; while (<>) { if (/^1\(P1\).*\s(?P<two_vars>\w+\s+\w+)\s+PROCESSED .* TIME .* KSINA=.*$/) { # Start new section $line_prefix = $+{two_vars}; $have_age_col = 0; $age_col = undef; } if (/^AGE /) { $have_age_col = 1; } if ($have_age_col && /^\s{0,5}(\d+)/) { $age_col = substr " ".$1, -5; } if (/^THN /) { die "THN encountered without header" unless $line_prefix; die "THN encountered without age column" unless $have_age_col and $age_col; s/^THN \s*//; s/\s+$//; my $output = "$line_prefix $age_col $_\n"; print STDOUT $output; } }
Verifying output to "Find the numbers between 1 and 1000 whose prime factors' sum is itself a prime" from Allain's Jumping into C++ (ch7 #3)
The question: Design a program that finds all numbers from 1 to 1000 whose prime factors, when added together, sum up to a prime number (for example, 12 has prime factors of 2, 2, and 3, which sum to 7, which is prime). Implement the code for that algorithm. I modified the problem to only sum unique factors, because I don't see why you'd count a factor twice, as in his example using 12. My solution. Is there any good (read: automated) way to verify the output of my program? Sample output for 1 to 1000: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 17 19 20 22 23 24 25 26 28 29 30 31 34 37 40 41 43 44 46 47 48 49 52 53 58 59 60 61 63 67 68 70 71 73 76 79 80 82 83 88 89 92 94 96 97 99 101 103 107 109 113 116 117 118 120 121 124 127 131 136 137 139 140 142 147 148 149 151 153 157 160 163 164 167 169 171 172 173 176 179 181 184 188 189 191 192 193 197 198 199 202 207 210 211 212 214 223 227 229 232 233 239 240 241 244 251 252 257 261 263 268 269 271 272 273 274 275 277 279 280 281 283 286 289 292 293 294 297 298 306 307 311 313 317 320 325 331 332 333 334 337 347 349 351 352 353 358 359 361 367 368 369 373 376 379 382 383 384 388 389 394 396 397 399 401 404 409 412 414 419 421 423 424 425 428 431 433 439 443 449 454 457 459 461 462 463 464 467 468 472 475 478 479 480 487 491 495 499 503 509 513 521 522 523 524 529 531 538 539 541 544 546 547 548 549 550 557 560 561 562 563 567 569 571 572 575 577 587 588 593 594 599 601 603 604 605 607 612 613 617 619 621 622 628 631 639 640 641 643 646 647 651 652 653 659 661 664 668 673 677 683 684 691 692 694 701 704 709 712 714 718 719 725 726 727 733 736 738 739 741 743 751 752 756 757 759 761 764 765 768 769 772 773 775 777 783 787 792 797 798 801 809 811 821 823 825 827 828 829 833 837 838 839 841 846 847 848 850 853 856 857 859 862 863 873 877 881 883 887 891 892 903 904 907 908 909 911 918 919 922 925 928 929 932 937 941 944 947 953 954 957 960 961 966 967 971 975 977 981 983 991 997 999 Update: I have solved my problem and verified the output of my program using an OEIS given series, as suggested by #MVW (shown in the source given by my new github solution). In the future, I will aim to test my programs by doing zero or more of the following (depending on the scope/importance of the problem): google keywords for an existing solution to the problem, comparing it against my solution if I find it unit test components for correctness as they're built and integrated, comparing these tests with known correct outputs
Some suggestions: You need to check the properties of your calculated numbers. Here that means calculating the prime factors and calculating their sum and testing if that sum is a prime number. Which is what your program should do in the first place, by the way. So one nice option for checking is comparing your output with a known solution or the output of a another program which is known to work. The tricky bit is to have such a solution or program available. And I neglect that your comparison could be plagued by errors as well :-) If you just compare it with other implementations, e.g. programs from other folks here, it would turn out more of a voting, it would not be a proof. It would just give increased probability that your program is correct, if several independent implementations come up with the same result. Of course all implementations could err :-) The more agree the better. And the more diverse the implementations are, the better. E.g. you could use different programming languages, algebraic systems or a friend with time and paper and pencil and Wikipedia. :-) Another means is to add checks to your intermediate steps, to get more confidence in your result. Kind of building a chain of trust. You could output the prime factors you determined and compare it with the output of a prime factorization program which is known to work. Then you check if your summing works. Finally you could check if the primality test you apply to the candidate sums is working correctly by feeding it with known prime numbers and non prime numbers and so on. That is kind of what folks do with unit testing for example. Trying to cover most parts of the code as working, hoping if the parts work, that the whole will work. Or you could formally prove your program step by step, using Hoare Calculus for example or another formal method. But that is tricky, and you might end up shifting program errors to errors in the proof. And today, in the era of internet, of course, you could internet search for the solution: Try searching for sum of prime factors is prime in the online encyclopedia of integer sequences, which should give you series A100118. :-) It is the problem with multiplicity, but shows you what the number theory pros do, with Mathematica and program fragments to calculate the series, the argument for the case of 1 and literature. Quite impressive.
Here's the answer I get. I exclude 1 as it has no prime divisors so their sum is 0, not a prime. Haskell> filter (isPrime . sum . map fst . primePowers) [2..1000] [2,3,4,5,6,7,8,9,10,11,12,13,16,17,18,19,20,22,23,24,25,27,29,31,32,34,36,37,40, 41,43,44,47,48,49,50,53,54,58,59,61,64,67,68,71,72,73,79,80,81,82,83,88,89,96,97 ,100,101,103,107,108,109,113,116,118,121,125,127,128,131,136,137,139,142,144,149 ,151,157,160,162,163,164,165,167,169,173,176,179,181,191,192,193,197,199,200,202 ,210,211,214,216,223,227,229,232,233,236,239,241,242,243,250,251,256,257,263,269 ,271,272,273,274,277,281,283,284,288,289,293,298,307,311,313,317,320,324,328,331 ,337,343,345,347,349,352,353,358,359,361,367,373,379,382,383,384,385,389,390,394 ,397,399,400,401,404,409,419,420,421,428,431,432,433,435,439,443,449,454,457,461 ,462,463,464,467,472,478,479,484,486,487,491,495,499,500,503,509,512,521,523,529 ,538,541,544,547,548,557,561,562,563,568,569,570,571,576,577,578,587,593,595,596 ,599,601,607,613,617,619,622,625,630,631,640,641,643,647,648,651,653,656,659,661 ,665,673,677,683,691,694,701,704,709,714,715,716,719,727,729,733,739,743,751,757 ,759,761,764,768,769,773,777,780,787,788,795,797,798,800,808,809,811,819,821,823 ,825,827,829,838,839,840,841,853,856,857,858,859,862,863,864,877,881,883,885,887 ,903,907,908,911,919,922,924,928,929,930,937,941,944,947,953,956,957,961,967,968 ,971,972,977,983,991,997,1000] Haskell> primePowers 12 [(2,2),(3,1)] Haskell> primePowers 14 [(2,1),(7,1)] You could hard-code this list in and test against it. I'm pretty confident these results are without error. (read . is "of").
Why is _beginthreadex failing with ERROR_INVALID_ACCESS?
I have a bunch of QWebViews rendered onto a widget. There comes a point at which I start getting the error QThread::start: Failed to create thread (The access code is invalid.). Looking at the Qt source, it appears that _beginthreadex is returning a null handle and errno is ERROR_INVALID_ACCESS, but I have no idea why. Here is the backtrace at the printing of the error: 0 qErrnoWarning qglobal.cpp 2451 0x69ccdd3c 1 QThread::start qthread_win.cpp 469 0x69cd5831 2 QThreadPoolPrivate::tryStart qthreadpool.cpp 203 0x69ccc3f5 3 QThreadPool::start qthreadpool.cpp 474 0x69cccdf4 4 QHostInfoLookupManager::work qhostinfo.cpp 633 0x6cb9b071 5 QHostInfoLookupManager::scheduleLookup qhostinfo.cpp 652 0x6cb9b143 6 QHostInfo::lookupHost qhostinfo.cpp 202 0x6cb9a220 7 qt_qhostinfo_lookup qhostinfo.cpp 722 0x6cb9b4b6 8 QAbstractSocket::connectToHostImplementation qabstractsocket.cpp 1427 0x6cbb17f5 9 QAbstractSocket::qt_static_metacall moc_qabstractsocket.cpp 166 0x6cbb4925 10 QMetaMethod::invoke qmetaobject.cpp 1664 0x69dc784f 11 QMetaObject::invokeMethod qmetaobject.cpp 1179 0x69dc6d6b 12 QMetaObject::invokeMethod qobjectdefs.h 418 0x6cd361dd 13 QAbstractSocket::connectToHost qabstractsocket.cpp 1342 0x6cbb13b3 14 QSslSocket::connectToHostImplementation qsslsocket.cpp 1744 0x6cbc7340 15 QSslSocket::qt_static_metacall moc_qsslsocket.cpp 91 0x6cbc93cf 16 QMetaMethod::invoke qmetaobject.cpp 1664 0x69dc784f 17 QMetaObject::invokeMethod qmetaobject.cpp 1179 0x69dc6d6b 18 QMetaObject::invokeMethod qobjectdefs.h 418 0x6cd361dd 19 QAbstractSocket::connectToHost qabstractsocket.cpp 1342 0x6cbb13b3 20 QSslSocket::connectToHostEncrypted qsslsocket.cpp 422 0x6cbc55e1 21 QHttpNetworkConnectionChannel::ensureConnection qhttpnetworkconnectionchannel.cpp 607 0x6cb6191f 22 QHttpNetworkConnectionPrivate::_q_startNextRequest qhttpnetworkconnection.cpp 862 0x6cb5e92c 23 QHttpNetworkConnectionPrivate::queueRequest qhttpnetworkconnection.cpp 501 0x6cb5c57d 24 QHttpNetworkConnection::sendRequest qhttpnetworkconnection.cpp 931 0x6cb5edf2 25 QHttpThreadDelegate::startRequest qhttpthreaddelegate.cpp 291 0x6cb8912a 26 QHttpThreadDelegate::qt_static_metacall moc_qhttpthreaddelegate_p.cpp 113 0x6cbd147c 27 QMetaCallEvent::placeMetaCall qobject.cpp 525 0x69dcf91c 28 QObject::event qobject.cpp 1195 0x69dd08db 29 QApplicationPrivate::notify_helper qapplication.cpp 4551 0x2582f44 30 QApplication::notify qapplication.cpp 3933 0x25808b7 31 QCoreApplication::notifyInternal qcoreapplication.cpp 915 0x69dc0dc6 32 QCoreApplication::sendEvent qcoreapplication.h 231 0x69e35185 33 QCoreApplicationPrivate::sendPostedEvents qcoreapplication.cpp 1539 0x69dc1d2a 34 qt_internal_proc qeventdispatcher_win.cpp 496 0x69de2590 35 USER32!OffsetRect C:\Windows\syswow64\user32.dll 0 0x74cc62fa 36 ?? 0 0x152404 37 ?? 0 0x401 38 ?? 0 The code at the call looks like: d->handle = (Qt::HANDLE) _beginthreadex(NULL, d->stackSize, QThreadPrivate::start, //d->stackSize is 0 this, CREATE_SUSPENDED, &(d->id)); if (!d->handle) { qErrnoWarning(errno, "QThread::start: Failed to create thread"); d->running = false; d->finished = true; return; } Why is this happening and how do I fix it? EDIT: also of note, there are exactly 500 threads at the point in which this breaks.
There's a good chance you've run out of free address space in your process (for thread stacks) after creating 500 threads. On 32-bit Windows, processes only get 2GB of address space by default (the upper half of the address space being reserved for the kernel). 500 1MB thread stacks (the default size, Qt may go higher or lower) plus all the other allocations your process makes could easily be using that up. See this Old New Thing article for more. Possible fixes: If you know your QThreads don't need very big stacks, you can call QThread::setStackSize() to set a smaller size before starting the thread. Consider using a thread pool and/or just reducing the number of concurrent threads you start. It's unlikely that you have enough CPU cores to make 500+ threads productive. Use the Windows /3GB switch and make your application LARGE ADDRESS AWARE to get 3GB of user-mode address space. Go 64-bit (for 63 bits of user-mode address space).
Qt application killed because Out Of Memory (OOM)
I am running a Qt application on embedded Linux platform. The system has 128 MB RAM, 512MB NAND, no swap. The application uses a custom library for the peripherals, the rest are all Qt and c/c++ libs. The application uses SQLITE3 as well. After 2-3 hours, the machine starts running very slow, shell commands take 10 or so seconds to respond. Eventually the machine hangs, and finally OOM killer kills the application, and the system starts behaving at normal speed. After some system memory observations using top command reveals that while application is running, the system free memory is decreasing, while slab keeps on increasing. These are the snaps of top given below. The application is named xyz. At Application start : Mem total:126164 anon:3308 map:8436 free:32456 slab:60936 buf:0 cache:27528 dirty:0 write:0 Swap total:0 free:0 PID VSZ VSZRW^ RSS (SHR) DIRTY (SHR) STACK COMMAND 776 29080 9228 8036 528 968 0 84 ./xyz -qws 781 3960 736 1976 1456 520 0 84 sshd: root#notty 786 3676 680 1208 764 416 0 88 /usr/libexec/sftp-server 770 3792 568 1948 1472 464 0 84 {sshd} sshd: root#pts/0 766 3792 568 956 688 252 0 84 /usr/sbin/sshd 388 1864 284 552 332 188 0 84 udevd --daemon 789 2832 272 688 584 84 0 84 top 774 2828 268 668 560 84 0 84 -sh 709 2896 268 556 464 80 0 84 /usr/sbin/inetd 747 2828 268 596 516 68 0 84 /sbin/getty -L ttymxc0 115200 vt100 777 2824 264 444 368 68 0 84 tee out.log 785 2824 264 484 416 68 0 84 sh -c /usr/libexec/sftp-server 1 2824 264 556 488 64 0 84 init After some time : Mem total:126164 anon:3312 map:8440 free:9244 slab:83976 buf:0 cache:27584 dirty:0 write:0 Swap total:0 free:0 PID VSZ VSZRW^ RSS (SHR) DIRTY (SHR) STACK COMMAND 776 29080 9228 8044 528 972 0 84 ./xyz -qws 781 3960 736 1976 1456 520 0 84 sshd: root#notty 786 3676 680 1208 764 416 0 88 /usr/libexec/sftp-server 770 3792 568 1948 1472 464 0 84 {sshd} sshd: root#pts/0 766 3792 568 956 688 252 0 84 /usr/sbin/sshd 388 1864 284 552 332 188 0 84 udevd --daemon 789 2832 272 688 584 84 0 84 top 774 2828 268 668 560 84 0 84 -sh 709 2896 268 556 464 80 0 84 /usr/sbin/inetd 747 2828 268 596 516 68 0 84 /sbin/getty -L ttymxc0 115200 vt100 777 2824 264 444 368 68 0 84 tee out.log 785 2824 264 484 416 68 0 84 sh -c /usr/libexec/sftp-server 1 2824 264 556 488 64 0 84 init Funnily though, I can not see any major changes in the output of top involving the application itself. Eventually the application is killed, top output after that : Mem total:126164 anon:2356 map:916 free:2368 slab:117944 buf:0 cache:1580 dirty:0 write:0 Swap total:0 free:0 PID VSZ VSZRW^ RSS (SHR) DIRTY (SHR) STACK COMMAND 781 3960 736 708 184 520 0 84 sshd: root#notty 786 3724 728 736 172 484 0 88 /usr/libexec/sftp-server 770 3792 568 648 188 460 0 84 {sshd} sshd: root#pts/0 766 3792 568 252 0 252 0 84 /usr/sbin/sshd 388 1864 284 188 0 188 0 84 udevd --daemon 819 2832 272 676 348 84 0 84 top 774 2828 268 512 324 96 0 84 -sh 709 2896 268 80 0 80 0 84 /usr/sbin/inetd 747 2828 268 68 0 68 0 84 /sbin/getty -L ttymxc0 115200 vt100 785 2824 264 68 0 68 0 84 sh -c /usr/libexec/sftp-server 1 2824 264 64 0 64 0 84 init The dmesg shows : sh invoked oom-killer: gfp_mask=0xd0, order=2, oomkilladj=0 [<c002d4c4>] (unwind_backtrace+0x0/0xd4) from [<c0073ac0>] (oom_kill_process+0x54/0x1b8) [<c0073ac0>] (oom_kill_process+0x54/0x1b8) from [<c0073f14>] (__out_of_memory+0x154/0x178) [<c0073f14>] (__out_of_memory+0x154/0x178) from [<c0073fa0>] (out_of_memory+0x68/0x9c) [<c0073fa0>] (out_of_memory+0x68/0x9c) from [<c007649c>] (__alloc_pages_nodemask+0x3e0/0x4c8) [<c007649c>] (__alloc_pages_nodemask+0x3e0/0x4c8) from [<c0076598>] (__get_free_pages+0x14/0x4c) [<c0076598>] (__get_free_pages+0x14/0x4c) from [<c002f528>] (get_pgd_slow+0x14/0xdc) [<c002f528>] (get_pgd_slow+0x14/0xdc) from [<c0043890>] (mm_init+0x84/0xc4) [<c0043890>] (mm_init+0x84/0xc4) from [<c0097b94>] (bprm_mm_init+0x10/0x138) [<c0097b94>] (bprm_mm_init+0x10/0x138) from [<c00980a8>] (do_execve+0xf4/0x2a8) [<c00980a8>] (do_execve+0xf4/0x2a8) from [<c002afc4>] (sys_execve+0x38/0x5c) [<c002afc4>] (sys_execve+0x38/0x5c) from [<c0027d20>] (ret_fast_syscall+0x0/0x2c) Mem-info: DMA per-cpu: CPU 0: hi: 0, btch: 1 usd: 0 Normal per-cpu: CPU 0: hi: 42, btch: 7 usd: 0 Active_anon:424 active_file:11 inactive_anon:428 inactive_file:3 unevictable:0 dirty:0 writeback:0 unstable:0 free:608 slab:29498 mapped:14 pagetables:59 bounce:0 DMA free:692kB min:268kB low:332kB high:400kB active_anon:0kB inactive_anon:0kB active_file:4kB inactive_file:0kB unevictable:0kB present:24384kB pages_scanned:0 all_unreclaimable? no lowmem_reserve[]: 0 103 103 Normal free:1740kB min:1168kB low:1460kB high:1752kB active_anon:1696kB inactive_anon:1712kB active_file:40kB inactive_file:12kB unevictable:0kB present:105664kB pages_scanned:0 all_unreclaimable? no lowmem_reserve[]: 0 0 0 DMA: 3*4kB 3*8kB 5*16kB 2*32kB 4*64kB 2*128kB 0*256kB 0*512kB 0*1024kB 0*2048kB 0*4096kB = 692kB Normal: 377*4kB 1*8kB 4*16kB 1*32kB 2*64kB 0*128kB 0*256kB 0*512kB 0*1024kB 0*2048kB 0*4096kB = 1740kB 30 total pagecache pages 0 pages in swap cache Swap cache stats: add 0, delete 0, find 0/0 Free swap = 0kB Total swap = 0kB 32768 pages of RAM 687 free pages 1306 reserved pages 29498 slab pages 59 pages shared 0 pages swap cached Out of memory: kill process 774 (sh) score 339 or a child Killed process 776 (xyz) So it's obvious that there is a memory leak, it must be my app since my app is killed. But I am not doing any malloc s from the program. I have taken care as to limit the scope of variables so that they are deallocated after they are used. So I am at a complete loss as to why is slab increasing in the top output. I have tried http://valgrind.org/docs/manual/faq.html#faq.reports but didn't work. Currently trying to use Valgrind on desktop (since I have read it only works for arm-cortex) to check my business logic. Addittional info : root#freescale ~/Application/app$ uname -a Linux freescale 2.6.31-207-g7286c01 #2053 Fri Jun 22 10:29:11 IST 2012 armv5tejl GNU/Linux Compiler : arm-none-linux-gnueabi-4.1.2 glibc2.5 cpp libs : libstdc++.so.6.0.8 Qt : 4.7.3 libs Any pointers would be greatly appreciated...
I don't think the problem is directly in your code. The reason is obvious: your application space does not increase (both RSS and VSW do not increase). However, you do see the number of slabs increasing. You cannot use or increase the number of slabs from your application - it's a kernel-only thingie. Some obvious causes of slab size increase from the top of my head: you never really close network sockets you read many files, but never close them you use many ioctls I would run strace and look at its output for a while. strace intercepts interactions with the kernel. If you have memory issues, I'd expect repeated calls to brk(). If you have other issues, you'll see repeated calls to open without close.
If you have some data structure allocation, check for the correctness of adding children and etc.. I had similar bug in my code. Also if you make big and large queries to the database it may use more ram memory. Try to find some memory leak detector to find if there is any leak.