FreeBASIC MutexDestroy
目次→実行時ライブラリー参考→多重スレッド化サポート→MUTEXDESTROY←オリジナル・サイト
ミューテックスを破壊します。
構文:
用法:
Mutexdestroy( id )
パラメタ:
記述:
Mutexdestroy は、
Mutexcreate によって作成されたミューテックスを捨てます。
Mutexdestroy の呼び出しは、ミューテックスを使う全てのスレッドが、ミューテックスを使わなくなった後で、実行します。
例:
'' 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
方言差:
プラットホーム差:
- FreeBASIC の DOS バージョンは、スレッドを考慮しません。OS がスレッドをサポートしないからです。
- Linux では、スレッドは、常に作成された順に、開始されます。Win32 では、これを想定できません。
これは OS の問題で、FreeBASIC の問題ではありません。
QBからの違い:
参照:
ページ歴史:2016-03-13 04:48:41
日本語翻訳:WATANABE Makoto、原文著作者:JofersToonski
