Hi Chris, sorry for bothering you again. Am trying to use the pgenlib_read to read the genotype data at the moment. I noticed that we need the
PgenFileInfo object and it seems like that the procedure is somewhat like:
```
plink2::PgenFileInfo pgen_file_info;
plink2::PgenReader pgen_reader;
plink2::PreinitPgfi(&pgen_file_info);
plink2::PgenHeaderCtrl header_control;
uintptr_t cur_alloc_cacheline_ct;
uint32_t use_mmap = 0;
char error_log[2 * 131072]; // some kind of error string
auto reterr = plink2::PgfiInitPhase1( file_name,
num_variants, num_sample, use_mmap, &header_control, &pgen_file_info, &cur_alloc_cacheline_ct, error_log);
if (unlikely(reterr)) { throw std::runtime_error(error_log); }
auto alloc_size = plink2::calculate_alloc_size(cur_alloc_cacheline_ct * plink2::kCacheline); std::vector<unsigned char> pgfi_alloc(alloc_size);
uint32_t max_vrec_width = 0;
auto phase2_error = plink2::PgfiInitPhase2(
header_control, 0, 0, 1, 0, num_variants, &max_vrec_width, pgen_file_info,
pgfi_alloc->data(), &pgr_alloc_cacheline_ct, error_log);
if (unlikely(phase2_error)) {
throw std::runtime_error(error_log);
}
```
This seems to work well when we are not using multi-threading. However, if I use this code in multi-threaded environment, I always get BUS ERROR 10 the line before the plink2:PgfiInitPhase2 and the function never got caught. I have checked the pgfi_alloc is correctly sized and all the exact same script works when I was not putting it in a std::thread. but will fail if I put it in a std::thread (see pseudo code example in attached)
Was there any kind of limitation regarding how to use PgenFileInfo and PgenReader in multi-threaded environment? Are they thread safe?
Thank you