MCPcopy Create free account
hub / github.com/Singular/Singular / createThreadPool

Function createThreadPool

Singular/dyn_modules/systhreads/shared.cc:2127–2159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2125};
2126
2127static BOOLEAN createThreadPool(leftv result, leftv arg) {
2128 long n;
2129 Command cmd("createThreadPool", result, arg);
2130 cmd.check_argc(1, 2);
2131 cmd.check_arg(0, INT_CMD, "first argument must be an integer");
2132 if (cmd.ok()) {
2133 n = (long) cmd.arg(0);
2134 if (n < 0) cmd.report("number of threads must be non-negative");
2135 else if (n >= 256) cmd.report("number of threads too large");
2136 if (!have_threads && n != 0)
2137 cmd.report("in single-threaded mode, number of threads must be zero");
2138 }
2139 if (cmd.ok()) {
2140 ThreadPool *pool = new ThreadPool((int) n);
2141 pool->set_type(type_threadpool);
2142 for (int i = 0; i <n; i++) {
2143 const char *error;
2144 SchedInfo *info = new SchedInfo();
2145 info->scheduler = pool->scheduler;
2146 acquireShared(pool->scheduler);
2147 info->job = NULL;
2148 info->num = i;
2149 ThreadState *thread = newThread(Scheduler::main, info, &error);
2150 if (!thread) {
2151 // TODO: clean up bad pool
2152 return cmd.abort(error);
2153 }
2154 pool->addThread(thread);
2155 }
2156 cmd.set_result(type_threadpool, new_shared(pool));
2157 }
2158 return cmd.status();
2159}
2160
2161static BOOLEAN createThreadPoolSet(leftv result, leftv arg) {
2162 Command cmd("createThreadPoolSet", result, arg);

Callers

nothing calls this directly

Calls 13

acquireSharedFunction · 0.85
newThreadFunction · 0.85
new_sharedFunction · 0.85
check_argcMethod · 0.80
check_argMethod · 0.80
argMethod · 0.80
reportMethod · 0.80
set_typeMethod · 0.80
set_resultMethod · 0.80
statusMethod · 0.80
okMethod · 0.45
abortMethod · 0.45

Tested by

no test coverage detected