Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Microsoft.ML.FastTree/TreeEnsembleFeaturizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -735,14 +735,17 @@ private static IDataView AppendFloatMapper<TInput>(IHostEnvironment env, IChanne
bool identity;
var converter = Conversions.Instance.GetStandardConversion<TInput, ulong>(type, dstType, out identity);
var isNa = Conversions.Instance.GetIsNAPredicate<TInput>(type);
ulong temp = 0;

ValueMapper<TInput, Single> mapper;
if (seed == 0)
{
mapper =
(in TInput src, ref Single dst) =>
{
//Attention: This method is called from multiple threads.
//Do not move the temp variable outside this method.
//If you do, the variable is shared between the threads and results in a race condition.
ulong temp = 0;
Copy link
Contributor

@harishsk harishsk Mar 18, 2020

Choose a reason for hiding this comment

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

Very nice find! :-) Can you please add some comments about this change? Otherwise some future developer might want to "optimize" this and move it back.

Also, this pattern deserves more investigation. Do we have other mappers that are using variables set outside the mapper function definition? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, sure, I will add comments on this.


In reply to: 394130751 [](ancestors = 394130751)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sharwell do you have any tool recommendation to detect similar race condition issue either static code analyze or run time detection?


In reply to: 394131983 [](ancestors = 394131983,394130751)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No similar issue found from other mappers but mapper are not only function used in multi-threading condition and it is impossible to view for all similar issue.


In reply to: 394130751 [](ancestors = 394130751)

Copy link
Contributor

@sharwell sharwell Mar 18, 2020

Choose a reason for hiding this comment

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

I'm not aware of such a tool. It would be easier to write a more targeted tool that identified variables captured by a lambda so they could be reviewed for cases like this. #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, thanks


In reply to: 394334398 [](ancestors = 394334398)

if (isNa(in src))
{
dst = Single.NaN;
Expand All @@ -759,6 +762,10 @@ private static IDataView AppendFloatMapper<TInput>(IHostEnvironment env, IChanne
mapper =
(in TInput src, ref Single dst) =>
{
//Attention: This method is called from multiple threads.
//Do not move the temp variable outside this method.
//If you do, the variable is shared between the threads and results in a race condition.
ulong temp = 0;
if (isNa(in src))
{
dst = Single.NaN;
Expand Down