Add methd to restrict confinement of memory segments

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Unresolved
    • Priority: P4
    • None
    • Affects Version/s: repo-panama
    • Component/s: core-libs

      As the confinement properties of a memory segment are now orthogonal from lifetime (e.g. a MemorySegment.Scope is not about confinement), we might add a method on MemorySegment to create a confined view of an existing shared segment:

      MemorySegment asThreadConfined(Thread);

      This creates a segment view that can only be accessed by the specified thread. Rules:

      * If the original segment can be accessed by any thread, then we can specify any thread as parameter;
      * If the original segment is already confined, we can only re-assert thread-confinement (e.g. we cannot change the confinement thread).

      This method would be very useful for divide-and-conquer algorithms:

      ```
      MemorySegment segment = sharedArena.allocate(...);
      Thread[] threads = ...
      for (int i = 0 ; i < threads.length ; i++) {
          process(segment.asSlice(0, CHUNK_SIZE)
                 .asThreadConfined(threads[i]));
      }
      ```

            Assignee:
            Maurizio Cimadamore
            Reporter:
            Maurizio Cimadamore
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: