gcc (GCC) 4.1.2
c89
こんにちは、
マルチスレッド アプリケーションでロックとロック解除を行う必要がある場所を決定します。
コード スニペットを短くします。私はグローバルなチャネル構造を持っています。すなわち
typedef struct tag_channel channel_t;
struct tag_channel {....};
API を使用してメッセージ キューのチャネルを設定および処理する 3 つの関数があります。
私のメインスレッド#1はこの関数を呼び出します
apr_status_t set_ss7_channel_state(channel_t *channel)
{
/* API call to set channel - non-blocking ASYNC call that returns immediately
wait for event in evt_loop */
setChanState(channel);
}
生成されたスレッド #2 でイベント ループが開始されました。他の関数が同じチャネル購入をトリガーして、チャネルをメッセージ キューに入れる可能性があります。
static void* APR_THREAD_FUNC evt_loop(apr_thread_t *thd, void *data)
{
while(is_looping) {
/* Get event and channel from message API message queue */
waitevt();
if(channel_process(channel) != TRUE) {
/* clean up */
}
}
}
スレッド #2 から呼び出されたプロセス チャネル
apr_status_t channel_process(channel)
{
/* process channel here based on the event
/* lock channel */
/* do some processing */
/* unlock channel */
}
したがって、基本的に、呼び出しは単一のチャネルに対して次のように機能します。
1) setChanState(channel) thread #1 -> puts channel on an API message queue
2) evt_loop(...) thread #2 will retrieve the event and the channel structure
3) process_channel(channel) will process the channel on thread #2
このチャネルには他のイベントが存在する可能性があるため、チャネル構造をブロックする必要があるのでしょうか? channel_process にブロッキングを設定しました。
ご提案いただきありがとうございます。