1

私はたまたま Queued Spinlock に出くわし、C++ で実装したいと考えています。これに関する情報を少しグーグルで検索しましたが、適切なドキュメントを取得できませんでした。

ドキュメント/実装のヒントは大歓迎です。

前もって感謝します

マイケル・ブラウンが指摘したコードには、次の疑問があります

// represents processor in wait queue of the spinlock
struct qsl_entry
{

// next processor in the queue that is waiting to enter section
qsl_entry* next;

// indicates whether the access to section has been granted to processor
int state;

};

// queued spinlock
struct qsl
{

// the first processor in the queue that is waiting to enter section
qsl_entry* head;

};

// requests access to critical section guarded by the spinlock,
// if the section is already taken it puts processor to wait
// and insert it into queue
// lck - queued lock that used to guard section
// ent - entry that represent processor in queue of the spinlock
void lock_qsl(qsl* lck, qsl_entry* ent)
{
__asm
{
    mov eax, ent;
    mov ebx, lck;

    // prepare queue entry
    mov [eax], 0;
    mov edx, eax;
    mov [eax]qsl_entry.state, 1;

    // store it as the last entry of the queue -- Is this what is line is doing ?
    // ebx contains address of lck & [ ebx ] refers to address pointed by lck & 
    // it is over written to ent. eax now contains the memory the lck was pointing to.
    lock xchg [ebx],eax;

    // if the section available grant access to processor?
    test eax, eax;
    jz enter_section;
        // link new entry with the rest of queue -- really ? are we nt overwritting
        // the next pointer here ?
        mov [eax],edx

        // wait for processor's turn
        wait1:
            pause;
            cmp [edx]qsl_entry.state, 1;
            je wait1;

    enter_section:
 }
}

この実装は正しいですか? 私はそうは思わない!

4

1 に答える 1

3

問題のコードの作成者はこちら。まず、コードが正しいことを述べさせてください。ここにコードの詳細な説明を書きました: http://kataklinger.com/index.php/queued-spinlocks/

また、別の実装がありますが、これはやや単純ですが、これほど良くはありません (それでも正しい)。どこかで見つけられるかどうか見てみます。見つけた。両方の実装を含むディスカッションへのリンクは次のとおりです: http://forum.osdev.org/viewtopic.php?f=15&t=15389

最後の投稿には、キューに入れられたスピンロックについてさらに詳しく説明するリンクもあります: http://www.cs.rice.edu/~johnmc/papers/tocs91.pdf

ええ、私はパーティーに少し遅れましたが、私はほんの数日前にこの投稿を行い、コードのより良い説明を書くように促しました.

于 2013-04-06T23:26:49.247 に答える