Skip to content

2 isolates in one thread #810

Description

@Idodoqdo

I have 2 modules that initialize an isolate. As part of a feature, I connect them simultaneously to be able to switch between them. Can they exist like this if when executing code on one isolate, the second one is idle and vice versa

in both cases similar creation and storage

namespace executor_old
{

using StartupDataPtr = std::unique_ptr< v8::StartupData, std::function< void( v8::StartupData* ) > >;


thread_local IsolatePtr ThreadIsolate;
namespace executor_new::core
{

using StartupDataPtr = std::unique_ptr< v8::StartupData, std::function< void( v8::StartupData* ) > >;


IsolatePtr& GetThreadIsolate()
{
   static thread_local IsolatePtr THREAD_ISOLATE;
   return THREAD_ISOLATE;
}
IsolatePtr GetThreadIsolateInstance()
{
   if( GetThreadIsolate() != nullptr )
      return GetThreadIsolate();
   v8::Isolate* isolate;
   v8::Isolate::CreateParams create_params;

   {
      log::ScopedLogInterval<> logger( L"[ejs] new allocator" );
      create_params.array_buffer_allocator_shared =
         std::shared_ptr< v8::ArrayBuffer::Allocator >{ v8::ArrayBuffer::Allocator::NewDefaultAllocator() };
      create_params.snapshot_blob = IsolateStartupSnapshot::GetInstance().Get();
   }
   {
      log::ScopedLogInterval<> logger( L"[ejs] new isolate" );
      isolate = v8::Isolate::New( create_params );
   }
   {
      log::ScopedLogInterval<> logger( L"[ejs] isolate initialize" );
      isolate->SetFatalErrorHandler( FatalErrorCallback );
      isolate->SetOOMErrorHandler( OOMErrorCallback );
      GetThreadIsolate() = IsolatePtr( isolate, DisposeIsolate );
   }

   return GetThreadIsolate();
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions