1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Emscripten で std::thread, pthread なマルチスレッドコードはブラウザでは 2021/07 時点実質使え無さそうなメモ

Last updated at Posted at 2021-07-31

背景

std::thread や pthread でスレッド化している C/C++ コードを emcc で WebAssembly でブラウザで動かしたい.

スレッド有効

-s USE_PTHREADS=1 とすると有効になります.

情報

問題点

ただ, 現在の Firefox(2021/07/30 時点)や Chrome だと

SharedArrayBuffer is not defined エラーが出ます.

どうもフラグで有効にしないと使えないっぽい...?

しかも, セキュリティ上の問題により, 制約が強くなります.

SharedArrayBuffer 開発時に使うのが面倒になりそう...?
あと, Safari では SharedArrayBuffer 対応していません.

そもそも WebAssembly の thread はまだ議論中

WebAssembly 自体の(ネイティブ?) thread, まだ仕様として決まっているわけではありませんでした...

現状どうするか?

各種ブラウザに対応させたいなどとなると,
C++ で完結するのは諦めて, JavaScript 側で WebWorker あたりでタスクを建てて処理させるしかなさそうです...

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?