PhotonLibOS
PhotonLibOS copied to clipboard
build fs and thread test failed
Ubuntu 22.04 g++ version : 11.20 glibc version : 2.35
fs-test
the reason why fs test build failed : From glibc 2.24 onwards, the __malloc_initialize_hook variable has been removed from the API.It wasted me some time to find the answer.I thought it was caused by something changed by the mimmalloc(micsoft's malloc) I installed yesterday. Myabe we could remind users to check the version of glibc before compiling fs/test.
thread-test
I am not very familiar with c++ templates. I am very interested in your implementation of thread pool and want to learn the following. So please help me solve this problem.
build info :
FAILED: thread/test/CMakeFiles/test-thread.dir/test.cpp.o /usr/bin/c++ -I/home/susun/code/cpp/PhotonLibOS/include -mcrc32 -msse4.2 -O0 -g -fPIE -w -Wall -DGTEST_HAS_PTHREAD=1 -std=c++14 -MD -MT thread/test/CMakeFiles/test-thread.dir/test.cpp.o -MF thread/test/CMakeFiles/test-thread.dir/test.cpp.o.d -o thread/test/CMakeFiles/test-thread.dir/test.cpp.o -c /home/susun/code/cpp/PhotonLibOS/thread/test/test.cpp In file included from /home/susun/code/cpp/PhotonLibOS/thread/test/test.cpp:31: /home/susun/code/cpp/PhotonLibOS/thread/test/../thread11.h: In instantiation of ‘typename std::enable_if<(! std::is_void<decltype (& typename std::decay<_Tp>::type::operator())>::value), photon::thread*>::type photon::thread_create11(FUNCTOR&&, ARGUMENTS&& ...) [with FUNCTOR = thread11_lambda_Test::TestBody()::<lambda(photon::semaphore&)>&; ARGUMENTS = {photon::semaphore&}; typename std::enable_if<(! std::is_void<decltype (& typename std::decay<_Tp>::type::operator())>::value), photon::thread*>::type = photon::thread*; decltype (& typename std::decay<_Tp>::type::operator()) = void (thread11_lambda_Test::TestBody()::<lambda(photon::semaphore&)>::*)(photon::semaphore&) const; typename std::decay<_Tp>::type = std::decay<thread11_lambda_Test::TestBody()::<lambda(photon::semaphore&)>&>::type]’: /home/susun/code/cpp/PhotonLibOS/thread/test/test.cpp:1502:28: required from here /home/susun/code/cpp/PhotonLibOS/thread/test/../thread11.h:156:54: error: call of overloaded ‘thread_create11<thread11_lambda_Test::TestBody()::<lambda(photon::semaphore&)>&, photon::semaphore&>(const uint64_t&, thread11_lambda_Test::TestBody()::<lambda(photon::semaphore&)>&, photon::semaphore&)’ is ambiguous 156 | return thread_create11<FUNCTOR, ARGUMENTS...>( | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ 157 | DEFAULT_STACK_SIZE, std::forward<FUNCTOR>(f), | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 158 | std::forward<ARGUMENTS>(args)...); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We are still investigating this issue. High version gcc may have a different behavior when installing lambda to template functions.
When I rethink this problem, I find that the problem is not the template, but how we think lambda calls.
When you create a lambda, the compiler will generate an anonymous class with the operator () method. In other words, we should regard the lambda call as a class function call, not a function call.
So I changed the error code to this, and successfully compiled test-thread on my host, and passed all thread tests.
auto lambda = [](photon::semaphore &sem){
sem.signal(1);
};
photon::thread_create11(&decltype(lambda)::operator(),&lambda,sem);
It's because C++ 20 introduced template lambda.
High version gcc seems to obey this rule even if we have explicitly set -std=C++14.
That would cause template mismatch when using our old implementation.
So we have uploaded a small fix. https://github.com/alibaba/PhotonLibOS/pull/50
Could you try the latest code on your environment?
It was successfully compiled on my environment. thank you.