cmultithreadingcritical-sectioncritical-region

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.


Solution

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

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

    Therefore, there are no critical sections here.