Geschieht pthread_mutex_lock vor der Semantik

threadA gehe dieses Snippet durch

{
    global_a = 100;  // 1
    {
        pthread_mutex_lock(&b_mutex)
                ...
        pthread_mutex_unlock(&b_mutex)
    }  // 2
}

threadB gehe dieses Snippet durch

{
    {
        pthread_mutex_lock(&b_mutex)
                ...
        pthread_mutex_unlock(&b_mutex)
    }  // 3

    int tmp = global_a; // 4
}

und nehmen an, dass aus der Sicht eines Beobachters die Ausführungsreihenfolge tatsächlich @ is

threadA --- 1threadA --- 2threadB --- 3threadB --- 4

Kann den Code bei threadB"int tmp = global_a;" siehe was threadA bei @ geset"global_a = 100;"?

Jeder Vorschlag ist willkommen.

Antworten auf die Frage(4)

Ihre Antwort auf die Frage