linuxカーネルのpthread_mutex_lock
とpthread_cond_wait
に相当するものは何ですか?それらを使用する方法について説明します。シンプルな世界を提供してください。linuxカーネルのpthread_mutex_lockとpthread_cond_waitに相当します
答えて
- (ALSが言ったように):
mutex_lock()
とmutex_unlock()
と我々我々は(#include <linux/mutex.h>
から)mutex_init()
でそれを使用する前にと同等のため
- をミューテックスを初期化する必要があり
wait_event_interruptible()
とwake_up_interruptible()
、我々は(#include <linux/wait.h>
から)init_waitqueue_head()
カーネルモジュールがカーネルに直接リンクするため、カーネルスペースではライブラリ呼び出しを使用できません。
を使用でき:
mutex_lock()
& mutex_unlock()
彼らを通じ提供されていますlinux/mutex.h
私はずっと前(1999っぽい)Linuxカーネルのプログラミングのためのミューテックスと条件ライブラリを作り、以来、さまざまなプロジェクトで使用されています。
私はそれをLMC(linux mutexesと条件変数)と呼びました。これは、カーネルにミューテックスタイプが存在する前であった。
http://www.kylheku.com/~kaz/lmc.html
最近、私は、そのセマンティクスれるクールな新機能を追加「あきらめタイムアウト、条件変数を待つために同じ時間ポーリング、複数のファイルディスクリプタでとをミューテックスを放棄します。」
これは、さまざまな共有オブジェクトを監視し、更新のために同時にカーネルソケットと通信した、この内部カーネルスレッドを使用しました。
それをチェックアウト:
は/**
* Atomically give up the mutex and wait on the condition variable.
* Wake up if the specified timeout elapses, or if a signal is delivered.
* Additionally, also wait on the specified file descriptors to become
* ready, combining condition waiting with poll().
* KCOND_WAIT_SUCCESS means the condition was signaled, or one or more
* file descriptors are ready.
* Also, a negative value can be returned indicating an error!
* (The poll needs to dynamically allocate some memory for the wait table).
* The timeout is relative to the current time, specifying how long to sleep in
* jiffies (CPU clock ticks).
*/
int kcond_timed_wait_rel_poll(kcond_t *, kmutex_t *, long,
kcond_poll_t *, unsigned int);
kcond_poll_t
構造体の配列を作成し、あなたの自己を記入しなければならない何かであり、構造は次のようになります。あなたはソケット(struct socket *
)またはファイル(struct file *
)のいずれかを待つことができるようにタイプフィールドがあります:ミューテックスを
/**
* Structure for file-descriptor polling condition waits.
* This resembles struct pollfd, but uses a direct file descriptor
* pointer rather than a file descriptor number. Also,
* it contains the wait queue by which the process is enqueued
* to wait on that descriptor. Thus our poll function doesn't
* have to dynamically allocate wait queue tables. It gets
* them from this array! (But this means that the array cannot
* be used by multiple threads at the same time to do polling!)
*/
typedef struct {
kcond_poll_type_t type; /* Must set this. */
union { /* Must set union field according to type. */
struct file *file;
struct socket *sock;
} obj;
short events; /* And this. */
short revents; /* Check response in this. */
wait_queue_t wait; /* Internal, don't set. */
wait_queue_head_t *queue; /* Internal, don't set */
} kcond_poll_t;
- 1. pthread_mutex_lockとpthread_cond_wait /シグナルがデッドロックを引き起こす
- 2. 組み込みLinuxカーネルとデスクトップLinuxカーネルの相違
- 3. Linux上のBBEditに相当します。
- 4. modinfo()相当のINSIDEカーネル?
- 5. WaitCommEventに相当するLinux
- 6. CUDAカーネルのusleep()に相当しますか?
- 7. TclのLinux相当物
- 8. LinuxのC++でWIN32_FIND_DATAに相当する
- 9. solarisのfork1に相当するLinux
- 10. linuxの "mkdir -p"に相当するpowershell?
- 11. Winsock2のLSPに相当するLinux OSI
- 12. DOSの "start"コマンドに相当するLinux?
- 13. glibとlinuxカーネル
- 14. LinuxはWindowsのタイムアウトコマンドに相当しますか?
- 15. linux g ++のMSVC++ _wrenameに相当しますか?
- 16. PHPはLinuxのトップコマンドに相当します
- 17. Linux環境に相当するPyFMIパッケージ
- 18. Python .pyd linuxに相当する
- 19. 依存関係ウォーカーはLinuxに相当しますか?
- 20. Linux Mono .NET Windowsサービスに相当。
- 21. Linuxカーネル、iptablesのとvmallocサイズ
- 22. Linuxカーネルのインストール
- 23. Linuxカーネルのlist.h
- 24. Linuxカーネルのバディシステムアロケータ
- 25. Linuxカーネルのメジャーページフォルトハンドラ
- 26. Linuxカーネルのカスタムネットワークプロトコル
- 27. Linuxカーネルのピンマルチプレキシング
- 28. 相当のMac "cp -X" on Linux
- 29. Windows/Cygwinに相当するLinux画面と$()?
- 30. pthread_cond_signalとpthread_cond_wait、エラーチェック
でwait_queue_headを初期化し、pthread_cond_waitのためにすべき? – MOHAMED
カーネルモジュールを他のモジュールから待機させる方法。私はpthread_cond_waitに相当するものを探しています – MOHAMED
@MohamedKALLEL:そうするには[Wait Queue](http://people.netfilter.org/rusty/unreliable-guides/kernel-hacking/queues.html)のようなものが必要です –