Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inverter.cpp: avoid mess with simultaneous read/write operations #15

Merged
merged 1 commit into from
Apr 10, 2022

Conversation

dilyanpalauzov
Copy link
Contributor

When many inverter_poller at the same time send commands, the result is undefined.

This locks exclusively the configuration file, while the process is running, so that simultaneous instances have to wait until the file is released.

For some reason locking the device /dev/hidraw0 does not work for me, I get sometimes the output from previous runs. I suspect that when cInverter::query() does exceed the 2s timeout, it quits, and leaves the
response of its commands on the wire. For fd = /dev/hidraw0: tcflush(fd, TCOFLUSH); has no effect.

As a matter of fact, on my system I have increased the timeout in cInverter::query() to 15s and now it does always work correctly.

Also the program, when called with -1, could exit, while the thread is receiving data, this leaves the next invocation with some ready-data, which it is not expecting.

When many inverter_poller at the same time send commands, the result is undefined.

This locks exclusively the configuration file, while the process is running,
so that simultaneous instances have to wait until the file is released.

For some reason locking the device /dev/hidraw0 does not work for me,
I get sometimes the output from previous runs.  I suspect that when
cInverter::query() does exceed the 2s timeout, it quits, and leaves the
response of its commands on the wire.  For fd = /dev/hidraw0
    tcflush(fd, TCOFLUSH);
has no effect.

As a matter of fact, on my system I have increased the timeout in
cInverter::query() to 15s and now it does always work correctly.

Also the program, when called with -1, could exit, while the thread
is receiving data, this leaves the next invocation with some
ready-data, which it is not expecting.
dilyanpalauzov added a commit to dilyanpalauzov/skymax-demo that referenced this pull request Apr 9, 2022
manio#15

When many inverter_poller at the same time send commands, the result is undefined.

This locks exclusively the configuration file, while the process is running,
so that simultaneous instances have to wait until the file is released.

For some reason locking the device /dev/hidraw0 does not work for me,
I get sometimes the output from previous runs.  I suspect that when
cInverter::query() does exceed the 2s timeout, it quits, and leaves the
response of its commands on the wire.  For fd = /dev/hidraw0
    tcflush(fd, TCOFLUSH);
has no effect.

As a matter of fact, on my system I have increased the timeout in
cInverter::query() to 15s and now it does always work correctly.

Also the program, when called with -1, could exit, while the thread
is receiving data, this leaves the next invocation with some
ready-data, which it is not expecting.
@manio manio merged commit aaf646a into manio:master Apr 10, 2022
@dilyanpalauzov dilyanpalauzov deleted the multithreading_locks branch April 10, 2022 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants