49 Subject subject = new Subject();
50 subject.getPrincipals().add(new UserPrincipal("Duke"));
51
52 // Always observable in the same thread
53 Subject.callAs(subject, () -> check(0, Subject.current(), "Duke"));
54
55 // Observable in a new platform thread in ACC mode, but not in the SV mode
56 Subject.callAs(subject, () -> {
57 Thread.ofPlatform().start(() -> check(1, Subject.current(), usv ? null : "Duke")).join();
58 return null;
59 });
60
61 // Never observable in a new virtual thread
62 Subject.callAs(subject, () -> {
63 Thread.ofVirtual().start(() -> check(2, Subject.current(), null)).join();
64 return null;
65 });
66
67 // Observable in structured concurrency in SV mode, but not in ACC mode
68 Subject.callAs(subject, () -> {
69 try (var scope = new StructuredTaskScope<>()) {
70 scope.fork(() -> check(3, Subject.current(), usv ? "Duke" : null));
71 scope.join();
72 }
73 return null;
74 });
75
76 // Suggested way to pass the current subject into arbitrary
77 // threads. Grab one using current() and explicitly pass it
78 // into the new thread.
79 Subject.callAs(subject, () -> {
80 Subject current = Subject.current();
81 Thread.ofPlatform().start(() -> {
82 Subject.callAs(current, () -> check(4, Subject.current(), "Duke"));
83 }).join();
84 return null;
85 });
86
87 if (results.size() != 5 || results.containsValue(false)) {
88 System.out.println(results);
89 throw new RuntimeException("Failed");
|
49 Subject subject = new Subject();
50 subject.getPrincipals().add(new UserPrincipal("Duke"));
51
52 // Always observable in the same thread
53 Subject.callAs(subject, () -> check(0, Subject.current(), "Duke"));
54
55 // Observable in a new platform thread in ACC mode, but not in the SV mode
56 Subject.callAs(subject, () -> {
57 Thread.ofPlatform().start(() -> check(1, Subject.current(), usv ? null : "Duke")).join();
58 return null;
59 });
60
61 // Never observable in a new virtual thread
62 Subject.callAs(subject, () -> {
63 Thread.ofVirtual().start(() -> check(2, Subject.current(), null)).join();
64 return null;
65 });
66
67 // Observable in structured concurrency in SV mode, but not in ACC mode
68 Subject.callAs(subject, () -> {
69 var joiner = StructuredTaskScope.Joiner.awaitAll();
70 try (var scope = StructuredTaskScope.open(joiner)) {
71 scope.fork(() -> check(3, Subject.current(), usv ? "Duke" : null));
72 scope.join();
73 }
74 return null;
75 });
76
77 // Suggested way to pass the current subject into arbitrary
78 // threads. Grab one using current() and explicitly pass it
79 // into the new thread.
80 Subject.callAs(subject, () -> {
81 Subject current = Subject.current();
82 Thread.ofPlatform().start(() -> {
83 Subject.callAs(current, () -> check(4, Subject.current(), "Duke"));
84 }).join();
85 return null;
86 });
87
88 if (results.size() != 5 || results.containsValue(false)) {
89 System.out.println(results);
90 throw new RuntimeException("Failed");
|