1 /* The MIT/Expat License
3 Copyright (C) 2017 Genome Research Ltd.
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 DEALINGS IN THE SOFTWARE.
29 #include "htslib/bgzf.h"
30 #include "htslib/thread_pool.h"
32 int main(int argc
, char *argv
[]) {
34 fprintf(stderr
, "Usage: thrash_threads4 input.bam\n");
38 // Find a valid seek location ~64M into the file
41 BGZF
*fpin
= bgzf_open(argv
[1], "r");
42 uint64_t upos
= 0, uend
= 0;
44 for (i
= 0; i
< 100; i
++) {
45 if ((got
= bgzf_read(fpin
, buf
, 65536)) < 0)
49 int64_t pos
= bgzf_tell(fpin
);
50 while ((got
= bgzf_read(fpin
, buf
, 65536)) > 0) {
54 int64_t end
= bgzf_tell(fpin
);
57 // Ensure input is big enough to avoid case 3,4 below going off the end
59 if (uend
< upos
+ 10000000) {
60 fprintf(stderr
, "Please supply a bigger input file\n");
66 // Spam random seeks & reads
67 for (i
= 0; i
< 1000; i
++) {
69 fpin
= bgzf_open(argv
[1], "r");
70 int j
, eof
= 0, mt
= 0;
71 for (j
= 0; j
< 80; j
++) {
73 putchar('0'+n
); fflush(stdout
);
76 if (bgzf_seek(fpin
, 0LL, SEEK_SET
) < 0) puts("!");//abort();
80 if (bgzf_seek(fpin
, pos
, SEEK_SET
) < 0) puts("!");//abort();
84 if (bgzf_seek(fpin
, end
, SEEK_SET
) < 0) puts("!");//abort();
88 int l
= rand()%(n
==3?100000:100);
89 if (bgzf_read(fpin
, buf
, l
) != l
*(1-eof
)) abort();
97 bgzf_mt(fpin
, 8, 256);
103 if (bgzf_close(fpin
))