FreeBASIC マニュアルのトップに戻る

FreeBASIC MutexDestroy

目次→実行時ライブラリー参考→多重スレッド化サポートMUTEXDESTROY←オリジナル・サイト

MUTEXDESTROY 左にメニュー・フレームが表示されていない場合は、ここをクリックして下さい

←リンク元に戻る プログラム開発関連に戻る

ミューテックスを破壊します。

構文:
declare sub Mutexdestroy ( byval id as any ptr )

用法:
Mutexdestroy( id )

パラメタ:
id
破壊するミューテックスの、any ptr ハンドル。

記述:
Mutexdestroy は、Mutexcreate によって作成されたミューテックスを捨てます。
Mutexdestroy の呼び出しは、ミューテックスを使う全てのスレッドが、ミューテックスを使わなくなった後で、実行します。

ミューテックスの、より多くの一般情報について、Mutexcreate を参照下さい。

例:
例については、MutexcreateThreadcreate も参照下さい。

'' Mutexes を使って、スレッドを同期化します
'' "MutexLock" と "MutexUnlock" を含む行をコメント化すると、
'' スレッドは、同期しません。
'' そして、データの一部は、表示されないかもしれません。

Declare Sub thread1 ( param As Any Ptr )
Declare Sub thread2 ( param As Any Ptr )
Declare Sub teletype (ByVal text As String, ByVal x As Integer, ByVal y As Integer)

Dim Shared threadsync As Any Ptr
Dim Shared thread1handle As Any Ptr
Dim Shared thread2handle As Any Ptr

'' ミューテックスを作成して、スレッドを同期化します
threadsync = MutexCreate

'' スレッド 1 を呼びます
thread1handle = ThreadCreate (@thread1)
If thread1handle = 0 Then
    Print "Error creating thread1"
End If

'' スレッド 2 を呼びます
thread2handle = ThreadCreate (@thread2)
If thread2handle = 0 Then
    Print "Error creating thread1"
End If

'' 両方のスレッドが終わるまで待ちます
ThreadWait(thread1handle)
ThreadWait(thread2handle)

teletype "Testing.................", 1, 1
teletype "Testing again...........", 10, 1

'' teletype の使用を終える時、ミューテックを廃棄します
MutexDestroy threadsync

Sleep
End

'' スレッド 1 は、簡単な "teletype" ルーチンを呼びます
Sub thread1 ( param As Any Ptr )
    teletype "This is a test...", 4, 1
End Sub

'' スレッド 2 も同様にします
Sub thread2 ( param As Any Ptr )
    teletype "This is another test...", 7, 1
End Sub

'' teletype は、与えられた位置で、画面を横切って、若干のテキストを繰り広げます
Sub teletype (ByVal text As String, ByVal x As Integer, ByVal y As Integer)

    Dim i As Integer, a As Integer
    Dim text_length As Integer

    text_length = Len (text)

    For a = 0 To text_length
        '' MutexLockは、同期して走っている 2つのスレッドが、
        '' "x"、"y"、"a" を共有しないようにします
        MutexLock threadsync
        Locate x, (y+a)
        Print Chr (text[a])

        '' MutexUnlock は、他の使用のために、これらの変数を開放します
        MutexUnlock threadsync
        Sleep 25
   Next a
End Sub



方言差:
プラットホーム差:
QBからの違い:
参照:
多重スレッド化サポート に戻る
←リンク元に戻る プログラム開発関連に戻る
ページ歴史:2016-03-13 04:48:41
日本語翻訳:WATANABE Makoto、原文著作者:JofersToonski

ホームページのトップに戻る

表示-非営利-継承