I try to split fastq files into 'N' chunks using a simple CC program and htslib-C . It works fine:

    ./split2file -o TMP S1.R1.fq.gz S1.R2.fq.gz -n 10 



 but when I use a thread pool ( As far as I understand I can use one and only one thread pool for reading and writing the files ?)


    ./split2file -o TMP S1.R1.fq.gz S1.R2.fq.gz -n 10 -t 2
    [LOG] closing "TMP.00001.R1.fastq.gz" N=100.
    Segmentation fault

When I use threads I've got a SIGSEGV signal.



here is the gdb stacktrace:

```
#0  0x00007ffff718209b in pthread_cond_signal@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
#1  0x00007ffff7f56770 in hts_tpool_dispatch3 () from /CONDAS/users/ifb-tools/miniconda3/envs/samtools-1.15.1/lib/libhts.so.3
#2  0x00007ffff7f11d42 in mt_queue () from /CONDAS/users/ifb-tools/miniconda3/envs/samtools-1.15.1/lib/libhts.so.3
#3  0x00007ffff7f148e5 in bgzf_flush () from /CONDAS/users/ifb-tools/miniconda3/envs/samtools-1.15.1/lib/libhts.so.3
#4  0x00007ffff7f14b76 in bgzf_close () from /CONDAS/users/ifb-tools/miniconda3/envs/samtools-1.15.1/lib/libhts.so.3
#5  0x0000555555557a3d in PairedEnd::~PairedEnd() ()
#6  0x0000555555556bc3 in main ()
```

here is the code:

(removed)

What Am i doing wrong ?


answering my question:

i was calling  `hts_tpool_destroy(pool);` before closing the bgz output writers.