+ 2
I was rated 5 out of 10 for this code
Any feedback for this code of odd even printing using two threads? I discussed initially and got feedback that it is only worth of 5 out of 10. Feel free to share your suggestions to improve this code. https://sololearn.com/compiler-playground/cY6n1J39OmTj/?ref=app
9 Answers
+ 4
it feels over-engineered for such a simple task. But for demonstrating thread synchronization, i think it's ok..
maybe it was rated by people who were taught using namespace std is bad. I have no problem with it. For small demo scripts, I feel it reduces the visual clutter and improves readability. Just as long as one is aware that it's a footgun for bigger codebases.
as for it being functional, it's actually a plus for me. OOP is overused and adds a lot of unnecessary boilerplate. Functional and imperative styles go straight for the problem.
+ 4
Reported michs23 for spamming. Reasons: New user + invalid analysis of the code + unrelated link + fake website = spam bot. (The real NJ DMV is at https://www.nj.gov/mvc/).
+ 3
Brian
i was wondering what the race conditions comment was about... it was clearly being addressed to in the code.
If this is a bot, it's context recognition is scarily getting better. It can now recognize the topic is about multi threading
+ 2
What's the criteria?
Improve in which direction?
+ 2
Any point is fine. Code readability, code quality, performance enhancement etc.
One point I got is the functional paradigm and global variables. It could have been avoided
+ 2
Hard to give feedback without knowing what the goal/grading criteria were.
You mentioned global variables counting against you.
Possibly declare and initialize your 3 global variables inside main() and then pass them as arguments to your 2 functions, like you did with maxNum.
+ 2
Bob_Li yes, it is a concerning level of sophistication, like they are testing for weakness and continually revising to become undetectable. I didn't click on the link, as I assume it is for phishing or installing malware.
+ 1
Ok. Will change it. Regarding goal of the exercise, it's like trying to implement a better code for printing odd and even numbers with thread synchronization
+ 1
The biggest problem is the race condition. Both threads are accessing and modifying the shared number variable without any synchronization. This means the output can be completely unpredictable. You'll often see numbers printed out of order, or even the same number printed multiple times. https://www.newjerseynjdmv.com