我写了一个写了一个程序,它没有像我期望的那样工作.我有两个线程:thread触发器func和anotherThread触发器anotherFunc.我想做的是当cont达到值10时func,anotherThread使用pthread_cond_wait和触发pthread_cond_signal.奇怪的是,如果我取消注释,一切正常sleep(1).我是线程的新手,我在这里遵循教程,如果我sleep在他们的例子中评论该行,它也会中断.
我的问题是如何在没有任何sleep()电话的情况下完成这项工作?如果在我的代码中func达到pthread_mutex_lock之后会发生什么anotherFunc?我该如何控制这些东西?这是我的代码:
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
pthread_mutex_t myMutex;
pthread_cond_t cond;
pthread_attr_t attr;
int cont;
void *func(void*)
{
printf("func\n");
for(int i = 0; i < 20; i++)
{
pthread_mutex_lock(&myMutex);
cont++;
printf("%d\n", cont);
if(cont == 10)
{
printf("signal:\n");
pthread_cond_signal(&cond);
// sleep(1);
}
pthread_mutex_unlock(&myMutex);
} …Run Code Online (Sandbox Code Playgroud) 这是我的小例子:...........
Mark <- paste ("SN", 1:400, sep = "")
highway <- rep(1:4, each = 100)
set.seed (1234)
MAF <- rnorm (400, 0.3, 0.1)
PPC <- abs (ceiling( rnorm (400, 5, 5)))
set.seed (1234)
Position <- round(c(cumsum (rnorm (100, 5, 3)),
cumsum (rnorm (100, 10, 3)), cumsum (rnorm (100, 8, 3)),
cumsum (rnorm (100, 6, 3))), 1)
mydf <- data.frame (Mark, highway, Position, MAF, PPC)
Run Code Online (Sandbox Code Playgroud)
我想过滤PPC的数据小于10,同时大于0.3的MAF.
# filter PPC < 10 & MAF > 0.3
filtered <- mydf[mydf$PPC < 10 & …Run Code Online (Sandbox Code Playgroud) 例如a > b,我们知道C中的条件导致0或1.如果我们想在表达式中直接使用这个0/ 1值,例如1 - (a > b),我们应该假设它是有符号的或无符号的(因为它可以产生差异)表达式)?标准对此有何看法?
以下是来自spoj的问题的实现: - http://www.spoj.com/problems/COINS/
#include <stdio.h>
#define ll long long
ll arr[100000];
ll max(ll n)
{
if(n < 49999)// Doubt
{
if(!arr[n])
return arr[n] = max(n/2) + max(n/3) + max(n/4);
else
return arr[n];
}
else
return max(n/2) + max(n/4) + max(n/3);
}
int main()
{
ll n, c = 0, i;
for(i = 0; i < 12; i++) // Also why 12 when the input can be <12
{
arr[i] = i;
}
while(scanf("%lld", &n) != EOF)
{
printf("%lld\n", max(n));
} …Run Code Online (Sandbox Code Playgroud) 我有一个数据框:
import pandas as pd
df = pd.DataFrame(np.random.randn(2, 4))
print(df)
0 1 2 3
0 1.489198 1.329603 1.590124 1.123505
1 0.024017 0.581033 2.500397 0.156280
Run Code Online (Sandbox Code Playgroud)
我想选择至少有一行值大于的列2。我尝试了以下操作,但是没有按预期工作。
df[df.columns[df.iloc[(0,1)]>2]]
Run Code Online (Sandbox Code Playgroud)
在这个玩具示例中,我的预期输出为:
2
1.590124
2.500397
Run Code Online (Sandbox Code Playgroud) 如果a = false并且b = 2是否有一种简洁的方法来实现这一点?使用只return a unless b返回 'nil' 而不是 '2'。
我有
def checkit
return a unless b
b
end
Run Code Online (Sandbox Code Playgroud)
这个语句会调用 b 两次吗?
一个真实的案例是:
def current_user
@current_user ||= authenticate_user
end
def authenticate_user
head :unauthorized unless authenticate_from_cookie
end
def authenticate_from_cookie
.
if user && secure_compare(user.cookie, cookie)
return user
else
return nil
end
end
Run Code Online (Sandbox Code Playgroud) 假设我有一个在 integer 上使用循环的函数i。现在出了点问题,我假设错误发生在i=5. 现在我可以逐步完成每一步(到目前为止我所做的)。
但现在我看了一下condition和text论证browser和debug:
text输入浏览器时可以检索的文本字符串。
条件 进入浏览器时可以检索的条件。
是否可以按照我想要的方式使用参数?
这是一个例子。调试器/浏览器应该只在i=5到达后启动:
fun <- function(x, y, n) {
result <- 0
for (i in 1:n) {
# browser(condition = (i == 5)) # does not work
result <- result + i * ( x + y)
}
return(result)
}
x <- 2
y <- 3
n <- 10
# debug(fun, condition = (i == 5)) # does …Run Code Online (Sandbox Code Playgroud) 我有一个 powershell 脚本,我从 Jenkins 那里接收元素名称作为变量:
$IISarray = @("$ENV:Cashier_NAME", "$ENV:Terminal_NAME", "$ENV:Content_Manager_NAME", "$ENV:Kiosk_BO_NAME")
foreach ($string in $IISarray){
"some code goes here"
}
Run Code Online (Sandbox Code Playgroud)
有时随机元素可以为空。如何添加检查以查看数组中的当前元素是否为空,跳过它并转到下一个元素?
我有一个需要输入的组件.. @Input() coDeliveryCandidates: DeliverySlotView[];
这在模板中使用:
<ng-container *ngFor="let coDeliverySlotView of (coDeliveryCandidates | async)">
<button
mat-raised-button
[color]=""
>
{{ label }}
</button>
</ng-container>
Run Code Online (Sandbox Code Playgroud)
color 属性需要一个字符串作为值,我想做一些类似的事情:
[color]="{
black: coDeliverySlotView.slotId === bookedSlot.slotId,
grey: !coDeliverySlotView.slotId === bookedSlot.slotId
}"
Run Code Online (Sandbox Code Playgroud)
在这里,我使用与 ngClass 相同的语法,但我想它不支持这种方式..那么还有哪些其他类似的方式呢?:)
conditional-statements angular-material angular-components angular
我目前有一个跟踪已完成 5 次测试的数据集,但是它只显示那些已完成测试的人,而不是那些尚未参加的人 - 示例如下:
Name Test Completed
John Math-Test1 Yes
John Math-Test2 Yes
John Math-Test3 Yes
John Math-Test4 Yes
John Math-Test5 Yes
Lauren Math-Test1 Yes
Lauren Math-Test2 Yes
Lauren Math-Test3 Yes
Tom Math-Test1 Yes
Tom Math-Test2 Yes
Tom Math-Test3 Yes
Tom Math-Test4 Yes
Tom Math-Test5 Yes
Run Code Online (Sandbox Code Playgroud)
如您所见,Lauren 尚未参加“Math-Test4”和“Math-Test5”测试,因此她的名字没有出现。我想添加一个选项,让“已完成”列在有人尚未完成测试时显示“否”。
所需的输出如下:
Name Test Completed
John Math-Test1 Yes
John Math-Test2 Yes
John Math-Test3 Yes
John Math-Test4 Yes
John Math-Test5 Yes
Lauren Math-Test1 Yes
Lauren Math-Test2 Yes
Lauren Math-Test3 Yes
*Lauren Math-Test4 No* …Run Code Online (Sandbox Code Playgroud)