HP-UX 11.31 で実行されているアプリケーションで現在のスレッドのスタック サイズを取得しようとしています。
Linux では を使用pthread_getattr_np
しましたが、Solaris では を使用できますthr_stksegment
。
Cでスレッドのスタックサイズを知る方法を見つけてください.
HP-UX 11.31 で実行されているアプリケーションで現在のスレッドのスタック サイズを取得しようとしています。
Linux では を使用pthread_getattr_np
しましたが、Solaris では を使用できますthr_stksegment
。
Cでスレッドのスタックサイズを知る方法を見つけてください.
この問題の解決策をWebkitソースで見つけました。ただし、スレッドの作成と一時停止はコストのかかる操作であるため、アプリケーションの高性能が非常に重要である場合、このソリューションは適していません。
Webkitソースでは、サイズではなくスタックベースを探しているため、base
単語をに置き換えます。size
コード例:
struct hpux_get_stack_size_data
{
pthread_t thread;
_pthread_stack_info info;
};
static void *hpux_get_stack_size_internal(void *d)
{
hpux_get_stack_base_data *data = static_cast<hpux_get_stack_size_data *>(d);
// _pthread_stack_info_np requires the target thread to be suspended
// in order to get information about it
pthread_suspend(data->thread);
// _pthread_stack_info_np returns an errno code in case of failure
// or zero on success
if (_pthread_stack_info_np(data->thread, &data->info)) {
// failed
return 0;
}
pthread_continue(data->thread);
return data;
}
static void *hpux_get_stack_size()
{
hpux_get_stack_size_data data;
data.thread = pthread_self();
// We cannot get the stack information for the current thread
// So we start a new thread to get that information and return it to us
pthread_t other;
pthread_create(&other, 0, hpux_get_stack_size_internal, &data);
void *result;
pthread_join(other, &result);
if (result)
return data.info.stk_stack_size;
return 0;
}