このタイプの質問は既に尋ねられていますが、私はエラーの理由を理解できません。エラー:クラス 'std :: result_of'にタイプ 'type'がありません
私は複数のスレッドを使用して、以下に示すように、ロックの実装をテストしようとしている:
class TTAS
{
atomic<bool> state;
public:
TTAS(){
state = ATOMIC_FLAG_INIT;
}
void lock() {
while(true) {
while(state) {};
// using exchange() which is equivalent to getAndSet but with lookup
if (!state.exchange(true)) {
return;
}
}
}
void unlock() {
state.exchange(false);
}
};
私は以下のコード使用して、このためのスレッドを作成しています:私はこのコードをコンパイルすると
void test2(TTAS t) {
}
TTAS t();
for (int i = 0; i < 10; i++) {
// Create a thread and push it into the thread list and call the distributedWrite function
threadList.push_back(std::thread(test2, std::ref(t)));
}
を私は以下のエラーを取得する。私はここで間違っていることを知りません。
In file included from /usr/include/c++/5/thread:39:0,
from assgn4.cpp:17:
/usr/include/c++/5/functional: In instantiation of ‘struct std::_Bind_simple<void (*(std::reference_wrapper<TTAS()>))(TTAS)>’:
/usr/include/c++/5/thread:137:59: required from ‘std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (&)(TTAS); _Args = {std::reference_wrapper<TTAS()>}]’
assgn4.cpp:186:60: required from here
/usr/include/c++/5/functional:1505:61: error: no type named ‘type’ in ‘class std::result_of<void (*(std::reference_wrapper<TTAS()>))(TTAS)>’
typedef typename result_of<_Callable(_Args...)>::type result_type;
^
/usr/include/c++/5/functional:1526:9: error: no type named ‘type’ in ‘class std::result_of<void (*(std::reference_wrapper<TTAS()>))(TTAS)>’
_M_invoke(_Index_tuple<_Indices...>)
^
誰かがこのエラーを説明できますか?事前
私は 'atomic'を 'atomic *'に変更しました。問題を修正しました。 –
anirudh
@anirudh私の最初のステップは、 'test2'がリファレンスを受け入れるようにしていましたが、あなたのユースケースを知っているので、あなたのソリューションは完全に有効で、最高のものになるでしょう。 – krzaq