|
50 | 50 | import com.oracle.graal.python.builtins.PythonBuiltinClassType;
|
51 | 51 | import com.oracle.graal.python.builtins.PythonBuiltins;
|
52 | 52 | import com.oracle.graal.python.builtins.objects.PNone;
|
| 53 | +import com.oracle.graal.python.builtins.objects.function.PKeyword; |
53 | 54 | import com.oracle.graal.python.builtins.objects.thread.PLock;
|
54 | 55 | import com.oracle.graal.python.builtins.objects.thread.PRLock;
|
55 | 56 | import com.oracle.graal.python.builtins.objects.thread.PThread;
|
56 | 57 | import com.oracle.graal.python.builtins.objects.type.PythonClass;
|
| 58 | +import com.oracle.graal.python.nodes.argument.keywords.ExecuteKeywordStarargsNode; |
| 59 | +import com.oracle.graal.python.nodes.argument.positional.ExecutePositionalStarargsNode; |
| 60 | +import com.oracle.graal.python.nodes.call.CallNode; |
57 | 61 | import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
|
58 | 62 | import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
|
59 | 63 | import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
|
60 |
| -import com.oracle.graal.python.nodes.thread.CreateThreadNode; |
| 64 | +import com.oracle.graal.python.runtime.PythonContext; |
61 | 65 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
| 66 | +import com.oracle.truffle.api.TruffleLanguage; |
62 | 67 | import com.oracle.truffle.api.dsl.Cached;
|
63 | 68 | import com.oracle.truffle.api.dsl.GenerateNodeFactory;
|
64 | 69 | import com.oracle.truffle.api.dsl.NodeFactory;
|
@@ -153,10 +158,23 @@ long getStackSize(long stackSize) {
|
153 | 158 | abstract static class StartNewThreadNode extends PythonBuiltinNode {
|
154 | 159 | @Specialization
|
155 | 160 | long start(VirtualFrame frame, PythonClass cls, Object callable, Object args, Object kwargs,
|
156 |
| - @Cached("create()") CreateThreadNode createThreadNode) { |
157 |
| - PThread thread = createThreadNode.execute(frame, cls, callable, args, kwargs); |
158 |
| - thread.start(); |
159 |
| - return thread.getId(); |
| 161 | + @Cached("create()") CallNode callNode, |
| 162 | + @Cached("create()") ExecutePositionalStarargsNode getArgsNode, |
| 163 | + @Cached("create()") ExecuteKeywordStarargsNode getKwArgsNode) { |
| 164 | + PythonContext context = getContext(); |
| 165 | + TruffleLanguage.Env env = context.getEnv(); |
| 166 | + |
| 167 | + // TODO: python thread stack size != java thread stack size |
| 168 | + // ignore setting the stack size for the moment |
| 169 | + Thread thread = env.createThread(() -> { |
| 170 | + Object[] arguments = getArgsNode.executeWith(args); |
| 171 | + PKeyword[] keywords = getKwArgsNode.executeWith(kwargs); |
| 172 | + callNode.execute(frame, callable, arguments, keywords); |
| 173 | + }, env.getContext(), context.getThreadGroup()); |
| 174 | + |
| 175 | + PThread pThread = factory().createPythonThread(cls, thread); |
| 176 | + pThread.start(); |
| 177 | + return pThread.getId(); |
160 | 178 | }
|
161 | 179 | }
|
162 | 180 | }
|
0 commit comments