2017-03-01 7 views
0

私は* .soライブラリを持っています。これはdlopenを使ってシステムライブラリからいくつかの情報を取得します。ライブラリは複数のアプリケーションで同時に使用できます。 多分それは愚かな質問ですが、dlopenを実行する前に私はライブラリーを集めるべきですか?私はどこでも直接答えを見つけられませんでした。dlopenの前にロックする必要がありますか?

+4

いいえ、それはライブラリをロードする際にすべてのプログラムは、独自のメモリ・スタックを使用しています。ロックは、同じ共有ライブラリを使用している複数のプログラムが存在しない場合には存在しない* shared resources *の場合のみです。 –

+0

ファイルを変更する人がいない場合は、そのファイルを群に入れる必要はありません。 –

+0

私は、ファイルシステム上のファイル(ライブラリ)への同時アクセスがさらに心配です。 – incogn1to

答えて

1

コメントに記載されているのと同様に、あなたが変更できる共有リソースにアクセスしていない限り、セマフォ(群)は必要ありません。 (IE。共有メモリにアクセスし、そのデータの並行性を確保する必要がある)。方法ダイナミックローディング...)(dlopenのは...のメモリ空間に行われているためGOT/PLTに働き、再配置および修正を結ぶ方法の

Those two routines are actually simple wrappers that call back into the dynamic linker. When the dynamic linker loads a library via dlopen(), it does the same relocation and symbol resolution it does on any other library, so the dynamically loaded program can without any special arrangements call back to routines already loaded

作品(dlopenを呼び出すプロセス)は、共有オブジェクトがマップされている場所ではありません。あなたが突然:)すっごくあなたに群れのための必要性を全く変えないそれらを心配する必要はありません、読み取り専用メモリにある共有オブジェクトを持つ

If a hundred processes use a shared library, it makes no sense to have 100 copies of the code in memory taking up space. If the code is completely read-only, and hence never, ever, modified

注:共有オブジェクトが他の共有オブジェクトにリンクしているため、最初の共有オブジェクトのGOTをdlopen()でロードされているライブラリの再配置で更新/ modする必要があります。プロセス固有のメモリ空間のar/wセグメントに、共有オブジェクトのar/wセグメントには格納されません。

the shared library must still have a unqiue data instance in each process...the read-write data section is always put at a known offset from the code section of the library. This way, via the magic of virtual-memory, every process sees its own data section but can share the unmodified code

関連する問題