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

EReg is not thread safe. #1173

Open
barisyild opened this issue Jan 2, 2025 · 2 comments
Open

EReg is not thread safe. #1173

barisyild opened this issue Jan 2, 2025 · 2 comments

Comments

@barisyild
Copy link

barisyild commented Jan 2, 2025

rc = match(start_match, mb->start_code, re->top_bracket, frame_size,

Rarely segmentation fault occurs on the line below, but usually match returns incorrectly.

var regex = new EReg("^[0-9]+", "");
for(i in 0...8)
{
    Thread.create(() -> {
        for (i in 0...1000000)
        {
            var str:String = "12312";
            if(regex.match(str))
            {
                // OK
            }else{
                // Wrong Result
                trace("Wrong Result");
            }
        }
    });
}
@Apprentice-Alchemist
Copy link
Contributor

This is entirely expected, EReg.match modifies internal state and is therefore not thread safe.

You should either create a new regex on each thread or use a mutex.
I don't think there's anything that can be done in the standard library or in hxcpp.

@barisyild
Copy link
Author

barisyild commented Jan 2, 2025

Can't make an hxcpp conditional macro that locks everything that isn't thread safe, so that if it can't lock it, can throw an exception and create a safer development environment?

For example, in languages ​​like Java, ConcurrentModificationException is returned in such cases.

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