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

about thread safe #129

Closed
nqf opened this issue Jun 13, 2024 · 1 comment
Closed

about thread safe #129

nqf opened this issue Jun 13, 2024 · 1 comment

Comments

@nqf
Copy link

nqf commented Jun 13, 2024

Is this thread safe ?

int main() {
  datadog::tracing::Tracer trace;

  std::thread([&] {
  auto maybe_span = trace.extract_or_create_span(reader, config);
  });
  std::thread([&] {
  auto maybe_span = trace.extract_or_create_span(reader, config);
  });
sleep(100);
}
@dgoffredo
Copy link
Contributor

dgoffredo commented Jun 14, 2024

To be pedantic, if and only if the reader is thread safe.

The Tracer member functions create_span, extract_span, and extract_or_create_span all instantiate a new TraceSegment and do not modify the invoked Tracer.

Those member functions could have been labeled const, but I left them non-const for possible future need. If such a need were to arrive, the maintainers would have to think about threading.

Here's an experimental commit that actually does make them const. All of the tests still pass.

Multiple new traces can be created from a single Tracer instance concurrently from multiple threads. It is thread safe.

See #44 for a (contrived) scenario that is not thread safe, but that is unrelated to your example.

@nqf nqf closed this as completed Jun 17, 2024
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

No branches or pull requests

2 participants