Jump to content

Annotation or Assert for thread correctness


TheGreyGhost

Recommended Posts

Howdy

 

After suffering a few sessions of debugging pain due to wrong side / wrong thread, I think it would be very helpful to add some sort of side / thread correctness checking to Forge - something that checks whether a method is being called from an unexpected thread, or at least gives an explicit cue.

 

Accessing client-side objects from the server side (or vica versa)

Calling methods from a side which is not used (for example - Item.onUpdate)

Rendering thread calling client thread code

Network thread calling client thread code or server thread code

 

The @SideOnly annotation in Forge helps a bit but isn't checked automatically (except by running the DedicatedServer and manually testing all code branches again), and it's also not suitable for decorating your own code with.

 

Some sort of static analysis with annotations would be best (during build, or during mod loading), but even a forge-provided assert method for coders would be very helpful.

 

If there is broad interest I can have a go at trying to produce something (advice on where to start would be very helpful since I don't have much experience with annotations)

 

-TGG

Link to comment
Share on other sites

Not really possible, and would be performance nightmares.

Also 90% of everything is called from both threads depending on what objects you are on.

@SideOnly has nothing to do with threads, its the environment.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.