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

Fix #505: remove data race in threaded CSV parser #511

Merged
merged 1 commit into from
Mar 19, 2019

Conversation

hcho3
Copy link
Contributor

@hcho3 hcho3 commented Mar 7, 2019

Minimal example to detect data race:

// example.cc
#include <dmlc/registry.h>
#include <dmlc/data.h>
#include <cstdint>

int main(void) {
  std::unique_ptr<dmlc::Parser<uint32_t, float>> parser(
    dmlc::Parser<uint32_t, float>::Create("data.txt", 0, 1, "csv"));
  parser->BeforeFirst();
  size_t total = 0;
  while (parser->Next()) {
    const auto& value = parser->Value();
    LOG(INFO) << "value.size = " << value.size;
    total += value.size;
  }
  LOG(INFO) << "total = " << total;

  return 0;
}

Content of data.txt: data.txt

To run the example:

  1. Checkout the latest master branch of dmlc-core.
  2. Set CFLAGS in Makefile of dmlc-core as follows:
# inside Makefile
export CFLAGS = -g -O0 -fsanitize=thread -Wall -Wno-unknown-pragmas -Iinclude
  1. Compile dmlc-core by invoking make at the project root of dmlc-core
  2. Compile example.cc by linking against dmlc-core:
g++ -g -O0 -fsanitize=thread -o example example.cc ./dmlc-core/libdmlc.a \
  -I./dmlc-core/include -lpthread -lgomp

You should see a long error trace, consisting of many occurrences of data race.

The proposed changes will remove all data race errors.

@hcho3 hcho3 changed the title Fix #505: data race in threaded CSV parser Fix #505: remove data race in threaded CSV parser Mar 7, 2019
Copy link
Member

@szha szha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! How does the speed look like before and after the change? This fix is necessary regardless, so the question is mostly out of curiosity.

@hcho3
Copy link
Contributor Author

hcho3 commented Mar 7, 2019

@szha I'll try to grab a large CSV file and do a performance test.

@hcho3 hcho3 merged commit 15362f8 into dmlc:master Mar 19, 2019
@hcho3 hcho3 deleted the fix_data_race branch March 19, 2019 00:40
eric-haibin-lin pushed a commit to eric-haibin-lin/dmlc-core that referenced this pull request Mar 24, 2019
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.

2 participants