Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@cherusker
Copy link
Contributor

Like suggested by @luhenry, I would like to propose this fix which was discussed in https://bugzilla.xamarin.com/show_bug.cgi?id=58423. As next_generic_inst_id is int, InterlockedIncrement64 () seems to be the right choice.

Also, I cannot add any reviewers or assignees, which is why I would kindly ask @lambdageek to review this as well :)

@dnfclas
Copy link

dnfclas commented Aug 2, 2017

@cherusker,
Thanks for having already signed the Contribution License Agreement. Your agreement was validated by .NET Foundation. We will now review your pull request.
Thanks,
.NET Foundation Pull Request Bot

@lewurm
Copy link
Contributor

lewurm commented Aug 2, 2017

int is usually 32bit, and anyway, id is defined as guint, so we should change the type of next_generic_inst_id. I guess really we should change both to guint32, so we are always sure that it is 32bit? And then use InterlockedIncrement.

@lewurm lewurm requested review from lambdageek and luhenry August 2, 2017 12:56
Copy link
Member

@lambdageek lambdageek left a comment

Choose a reason for hiding this comment

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

I agree with @lewurm let's make next_generic_inst_id and MonoGenericInst:id an explicitly sized type (so uint32_t)

@cherusker
Copy link
Contributor Author

cherusker commented Aug 2, 2017

@lewurm, @lambdageek: so far, InterlockedIncrement (), InterlockedAdd (), ... is only defined for signed types (gint32 and gint64) in atomic.h. IMO, there are two options if next_generic_inst_id and MonoGenericInst:id should be unsigned (which makes a lot of sense of course):

A cast from guint32 to gint32 and back (with the increment in-between) seems to work fine on Fedora 26 (also with high numbers) and it might work in general. However, is there any guarantee that all supported compilers will always cast that as we fancy it (and don't cap it for example)?

#include <stdint.h>
#include <stdio.h>

int main() {

	uint32_t x = -3;
	int32_t y = x;

	for (int i = 0; i < 5; ++i) {
		x = ++y;
		(void) printf("x = %u, y = %i\n", x, y);
	}
	
	return 0;
}

My second idea is to add something like InterlockedIncrementUnsigned (volatile guint32 *val) to atomic.h as the need for such a thing might arise again. I played with atomic.h before (https://github.com/mono/mono/pull/5255/files#diff-e4e234bb2d8469fbeb2e3d1b467919ea) and think it shouldn't be much hassle. Picking the right name might be the most difficult part.

@luhenry
Copy link
Contributor

luhenry commented Aug 2, 2017

@cherusker you can just do InterlockedIncrement((gint32*)value)

@vargaz
Copy link
Contributor

vargaz commented Aug 2, 2017

Just make them signed, no need to use unsigned types unless necessary, it just complicates things.

@vargaz
Copy link
Contributor

vargaz commented Aug 2, 2017

Looks ok, please squash the changes when committing.

- as discussed in https://bugzilla.xamarin.com/show_bug.cgi?id=58423
- in addition, unify `int` and `guint` into `gint32` which can be used flawlessly with `InterlockedIncrement ()`
@cherusker cherusker force-pushed the cherusker-2017-08-01-next-generic-inst-id branch from 0c3b534 to 47535f5 Compare August 2, 2017 19:21
@cherusker
Copy link
Contributor Author

@vargaz I thought that all commits get squashed automagically when a PR gets merged and, due to that, I usually keep many small commits if somebody wants to retrace a specific PR. Anyways - just squashed everything :)

@lewurm
Copy link
Contributor

lewurm commented Aug 2, 2017

we can squash and merge on the github UI that does that

@lewurm
Copy link
Contributor

lewurm commented Aug 2, 2017

@monojenkins merge

@monojenkins
Copy link
Contributor

cannot merge:

  • "Linux i386" state is "success"
  • "Linux x64" state is "failure"
  • "OS X i386" state is "success"
  • "OS X x64" state is "success"
  • "Windows i386" state is "success"
  • "Windows x64" state is "failure"

@monojenkins monojenkins merged commit 8bbca2b into mono:master Aug 2, 2017
@cherusker cherusker deleted the cherusker-2017-08-01-next-generic-inst-id branch August 3, 2017 06:48
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…-next-generic-inst-id

[metadata] Fix racy next_generic_inst_id

Like suggested by @luhenry, I would like to propose this fix which was discussed in https://bugzilla.xamarin.com/show_bug.cgi?id=58423. As `next_generic_inst_id` is `int`, `InterlockedIncrement64 ()` seems to be the right choice.

Also, I cannot add any reviewers or assignees, which is why I would kindly ask @lambdageek to review this as well :)


Commit migrated from mono/mono@8bbca2b
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.

7 participants