multithreading - boost thread with c++ 11lambda -


How do I use Boost Threads with C ++ 11 Lambda?

The following code is not function:

  int sum; M_workerThread = new boost: thread ([] () {for (int i = 0; i <100; i ++) {sum = sum + i;}});  

I'm getting the compilation error.

  Error 4 error C3493: can not be completely captured on 'Yoga' because no default capture mode is specified  

I How can I fix this?

According to the error, just to capture sum as is , Lambda does not know that sum is:

  m_workerThread = new boost :: thread ([and sum] () // ^ ^ ^ ^ For (int i = 0; i & lt; 100; i ++) {sum = sum + i;}});  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -