LouisCharlesC / safe

Header only read/write wrapper for mutexes and locks.
MIT License
147 stars 11 forks source link

It isn't working in my sample #13

Closed paulocoutinhox closed 5 years ago

paulocoutinhox commented 5 years ago

Hi,

It isn't working in my sample:

https://github.com/prsolucoes/cpp-thread-safe-container

Your library is inside "02-fluentcpp" and the output is on README file.

Thanks for any help.

LouisCharlesC commented 5 years ago

Hey there, I fail to see the problem. Your README states: "The working solution need output apple and potato counters with 5000 each.", and the test output from sample 02-fluentcpp is: "Result: apple = 5000, potato = 5000". That seems fair to me! I need more guidance :)

paulocoutinhox commented 5 years ago

Yes, i have updated on last week and appear work. Can you only see the source file to check if i have implemented correct please?

https://github.com/prsolucoes/cpp-thread-safe-container/blob/master/02-fluentcpp/src/main.cpp

LouisCharlesC commented 5 years ago

Yeah, that's the right way to use safe! If you wanted it to be absolutely perfect, you could replace the usage of the safe::WriteAccess in line 49 by a calls to myMap.unsafe(). Only one thread remains active at this point and locking the mutex is futile. Notice that you correctly did not lock the mutex in line 49 of the 03-std sample.

paulocoutinhox commented 5 years ago

OK, perfect. Thanks for your time. It will be very useful for us man. Thanks again.