我需要在c中用pthread制作莱布尼兹算法,现在我有了这段代码,但目前线程实现与顺序实现的时间相同,我认为它不是同时运行的。有人可以看到错误吗。
\n\n谢谢!!
\n\n#include<stdio.h>\n#include<math.h>\n#include<pthread.h>\n#include<stdlib.h>\n#define NUM_THREADS 2\n#define ITERATIONS 100000000\ndouble result = 0.0;\nvoid *leibniz(void *threadid){\n int size = ITERATIONS/NUM_THREADS;\n int start = (long)threadid * size;\n int end = ((long)threadid+1) * size;\n int i;\n for(i = start; i<end; i++){\n int denom = 2*i+1;\n result += pow(-1.0, i) * (1.0/denom);\n }\n}\n\nint main(){\n pthread_t threads[NUM_THREADS];\n long t;\n int rc;\n\n // CREATE\n for(t=0;t<NUM_THREADS;t++){\n rc = pthread_create(&threads[t], NULL, leibniz, (void *)t);\n if(rc){\n printf("ERROR: return code %d\\n", rc);\n }\n }\n // JOIN\n for(t=0;t<NUM_THREADS;t++){\n rc = pthread_join(threads[t], NULL);\n …Run Code Online (Sandbox Code Playgroud) 我需要在ejs模板中使用流程变量才能调用端点,但是从这种情况下,我无法到达流程nodejs变量。
我该如何实现?
<a class="imgLink" href="#" onclick="get_user_info()">
<div style="border: 2px solid gray;padding: 8px">Info</div>
</a>
<script>
function get_user_info() {
$.get(`/users/${process.env.userId}`, function(data) {
// Do something
})
}
</script>
Run Code Online (Sandbox Code Playgroud) 在Java中,可以执行以下操作:void function(Url... urls).它可以使用1..n网址.问题是,是否有可能与Kotlin做同样的事情.