繁体   English   中英

以下代码中是否有关键部分?

[英]Are there critical sections in the following code?

以下代码段在单个进程中被多个线程定期调用。 这里的问题是,是否有关键部分?

第一个代码:

struct object {
    struct object *nxt;
};

void delete(object **top, object *deletable) {
    object *current, *pred;
    if (*top == deletable) {
        *top = deletable->nxt;
} else {
    pred = top;
    current = (*top)->nxt;
    while (current && (current != deletable)) {
        pred = current;
        current = current->nxt;
    }
    if (current) {
        pred = current->nxt;
    }
}

第二密码;

int shift(int param) {
    int result = 654321;
    result = result ^ param;
    param = param * result;
    result = (param >> 9) ^ ~result;
    return result;
}

目前,我不认为有任何关键部分,因为变量不会操纵相同的数据。 但是我对此不确定。 我对关键部分和多线程很陌生。

您的代码中没有全局和/或静态变量。

没有其他类型的共享资源(例如,在不同位置使用的同一文件)。

因此,这里没有关键部分。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM