diff --git a/base/threading/platform_thread_posix.cc b/base/threading/platform_thread_posix.cc index 89ea7935b65c65ed3c6679d3dd6ad5ffc17a53c5..76a57a31e76ecbb773f2d5fcf18908a84b27b6b5 100644 --- a/base/threading/platform_thread_posix.cc +++ b/base/threading/platform_thread_posix.cc @@ -127,6 +127,18 @@ bool CreateThread(size_t stack_size, DCHECK(thread_handle); base::InitThreading(); +#if BUILDFLAG(IS_OHOS) +#if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) && BUILDFLAG(USE_STARSCAN) && BUILDFLAG(HAS_64_BIT_POINTERS) + // Ensure that PartitionAddressSpace::Init is executed on the main thread + // to avoid concurrency issues. + static bool partitionAddressSpaceInit = false; + if ((!partitionAddressSpaceInit) && (getpid() == gettid())) { + partition_alloc::internal::PartitionAddressSpace::Init(); + partitionAddressSpaceInit = true; + } +#endif +#endif + pthread_attr_t attributes; pthread_attr_init(&attributes);