スレッド調査

Mosh でのスレッドのあり方を考えるにあたっての下調べ。
SRFI-18 をサポートするならば、dynamic environment あたりに手を入れないといけない。(サポートしないという可能性 もあるけど)

SRFI-18

  • Thread
  • Mutex
    • Mutex にひもづくデータを持てる
  • Condition variable
    • ラッチ的
    • Condition variable にひもづくデータを持てる
  • Time
  • vector-ref/set! などは atomic ではない。ユーザーがケアする
    • 実装がこれをサポートしても良い
  • スレッドはそれぞれが独自の dynamic environment を持つ
  • srfi-21 に拡張で Real-time multithreading support というのがある
  • Continuation は別スレッドで実行する事も可能
  • (current-thread)
  • (thread? obj)
  • (make-thread thunk [name])
  • (thread-name thread)
  • (thread-specific thread)
  • (thread-specific-set! thread obj)
  • (thread-start! thread)
  • (thread-yield!)
  • (thread-sleep! timeout)
  • (thread-terminate! thread)
  • (thread-join! thread [timeout [timeout-val]])
  • (mutex? obj)
  • (make-mutex [name])
  • (mutex-name mutex)
  • (mutex-specific mutex)
  • (mutex-specific-set! mutex obj)
  • (mutex-state mutex)
  • (mutex-lock! mutex [timeout [thread]])
  • (mutex-unlock! mutex [condition-variable [timeout]])
  • (condition-variable? obj)
  • (make-condition-variable [name])
  • (condition-variable-name condition-variable)
  • (condition-variable-specific condition-variable)
  • (condition-variable-specific-set! condition-variable obj)
  • (condition-variable-signal! condition-variable)
  • (condition-variable-broadcast! condition-variable)
  • (current-time)

Gauche

srfi-18 を満たしている。
Gaucheのスレッドには、個別の仮想マシンが割り当てられ、専用のPOSIXスレッドにより実行される。

Ikarus

スレッド対応する予定。内部構造的には native thread, green thread どちらも対応可能。

Ypsilon

この辺りにメモが。先進的。
Parallel Schemeに向けたテストその4 - Y.FUJITA::NOTEPAD::YPSILON

PLT

10 Concurrency

  • green thread ?
  • set! などは全て atomic
  • semaphore
  • blocking queue(channel)
  • Thread local storage

Clojure

Ruby 1.9

結構制限が大きい。

ネイティブスレッドを用いて実装されていますが、 現在の実装では Ruby VM は Giant VM lock (GVL) を有しており、同時に実行される ネイティブスレッドは常にひとつです。 ただし、IO 関連のブロックする可能性があるシステムコールを行う場合には GVL を解放します。その場合にはスレッドは同時に実行され得ます。 また拡張ライブラリから GVL を操作できるので、複数のスレッドを 同時に実行するような拡張ライブラリは作成可能です。

class Thread

Python

pthread.

SBCL

pthread + futex

  • *current-thread*
  • make-thread function &key name
  • thread-alive-p
  • interrupt-thread-error
  • interrupt-thread-error-thread condition
  • terminate-thread thread
  • make-mutex &key name value
  • mutex-value instance
  • with-mutex
  • with-recursive-lock (mutex) &body body
  • waitqueue
  • make-waitqueue &key name
  • waitqueue-name instance