简体   繁体   中英

Are there critical sections in the following code?

The following code pieces are been called regularly by multiple threads in a single process. The question here is, are there critical sections?

First 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;
    }
}

Second Code;

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

Currently i don't think that there are any critical sections, because the variables don't manipulate the same data. But I am not sure about this. I am pretty new to critical sections and multithreading.

There are no global and/or static variables in your code.

There are no other types of shared resources (eg, the same file used in different places).

Therefore, there are no critical sections here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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