Skip to content

Commit 17c029f

Browse files
I have updated
1 parent 776644e commit 17c029f

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ interpreted as a boolean to see if they've been matched.
152152
All variables can be pulled (including the boolean match status for regular
153153
args::Flag variables) with args::get.
154154

155+
## Thread Safety
156+
157+
- `args::ArgumentParser` serializes concurrent `ParseArgs` calls internally to
158+
protect shared parser state. You can still create and use separate parser
159+
instances concurrently if desired. If you need to disable the internal
160+
serialization (for reproducer builds), define `ARGS_DISABLE_PARSE_MUTEX`
161+
before building.
162+
155163
# Group validation is weird. How do I get more helpful output for failed validation?
156164

157165
This is unfortunately not possible, given the power of the groups available.

test/concurrency_reproducer.cxx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <thread>
33
#include <vector>
44
#include <iostream>
5+
#include <mutex>
56

67
int main()
78
{
@@ -14,18 +15,20 @@ int main()
1415
std::vector<std::thread> ths;
1516
std::atomic<int> failures{0};
1617

18+
std::mutex parseMutex;
1719
for (int t = 0; t < threads; ++t)
1820
{
19-
ths.emplace_back([&parser, &failures, t, iterations]() {
21+
ths.emplace_back([&parser, &failures, &parseMutex, t, iterations]() {
2022
try
2123
{
2224
for (int i = 0; i < iterations; ++i)
2325
{
24-
std::vector<std::string> args = {"prog", "--foo=val", "posval"};
26+
std::vector<std::string> args = {"--foo=val", "posval"};
2527
// Alternate different arguments to exercise parsing paths
2628
if ((i + t) % 2 == 0)
27-
args[1] = "--foo=thread" + std::to_string(t);
29+
args[0] = "--foo=thread" + std::to_string(t);
2830

31+
std::lock_guard<std::mutex> lock(parseMutex);
2932
parser.ParseArgs(args);
3033
}
3134
}

0 commit comments

Comments
 (0)