Giter VIP home page Giter VIP logo

Comments (2)

rickgaiser avatar rickgaiser commented on May 12, 2024

I guess this depends on another descussion about how threads work on the IOP:

  • threads can only be interrupted by interrupts
  • interrupt handlers cannot call these functions

So we only need to worry about thread safety if another thread starts as a result from an interrupt while inside AllocSysMemory() or FreeSysMemory(). And there's been some discussion about whether this is possible or not.

Can an interrupt return to a higher priority thread? If so then these functions need to be thread safe, or called with interrupts disabled.

Why don't we make a simple test .irx, with 2 threads:

  • thread1: low priority, runs forever in a loop, calling AllocSysMemory() and FreeSysMemory()
  • thread2: high priority, triggered periodically with an interrupt, calling AllocSysMemory() and FreeSysMemory() once, then going back to sleep

If interrupts cannot return to a higher priority thread, then the IOP will be stuck inside thread1 (but I don't think this is the case).

If interrupts do return to the higher priority thread, then calling any thread-unsafe function will cause problems. Probably a memory leak, or crash.

from ps2sdk.

sp193 avatar sp193 commented on May 12, 2024

By the official documentation, it is possible for a higher-priority thread to be run instead of the previous running thread, if the higher-priority thread is changed into READY state by the interrupt handler. That would cause the previous running thread to be changed to READY state instead and the higher-priority thread will be changed from READY to RUN, when scheduling is resumed.

Even if it was not allowed, I was thinking that the AllocSysMemory function could be made to (accidentally) allocate the same region of memory twice, if the thread calling AllocSysMemory is suspended with iSuspendThread(), called by an interrupt handler. Another thread that runs could be allowed to execute AllocSysMemory(), which would then allow two threads to execute AllocSysMemory with the same (stale) state.

I am a little burned out now. But if nobody does any tests in a few days, I might do them.
Your test idea is great. But perhaps I'll do an additional check on whether both threads can somehow get the same memory pointer from AllocSysMemory, just in case the design does not allow a crash to occur. I can check for the amount of free memory too, I believe.

Thanks!

from ps2sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.