Comments (3)
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.
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.
The code for suspending/resuming interrupts in AllocSysMemory
and FreeSysMemory
was added at some point between 1.3.4 and 3.1.0. Pointers to CpuSuspendIntr
and CpuResumeIntr
are passed to loadcore
and sysmem
internal structures from modload
.
So, it is only thread safe if using the new modules.
So, basically:
- When using old modules, wrap the call between
CpuSuspendIntr
andCpuResumeIntr
- When using new modules, and you do not need compatibility with the old modules, you do not need to wrap the call
from ps2sdk.
Related Issues (20)
- How do I use ps2adpcm tool HOT 1
- MIPTBP1 and 2 incorrect bitmask HOT 2
- Why not add support for GB2312 encoding HOT 2
- cdrom filepaths broken by new changes to libcglue's __path_absolute() function HOT 1
- VU1 sample syncronization problem HOT 3
- The ps2dev sdk ships an incomplete opusfile install HOT 4
- [PROPOSAL]: dispatch IRX modules built by debug PS2SDK into the release section HOT 2
- Issue with `sleep` function HOT 7
- shortcomings in audsrv and upsampling HOT 4
- [DISCUSSION]: PPC toolchain on PS2SDK. Do we want it? HOT 4
- [MCMAN] different return value compared to sce modules. why? HOT 2
- ps2sdk now only works on latest pcsx2 HOT 5
- ELF loader broken HOT 1
- [FR] Replace non-working BIN2S and BIN2O with scripts HOT 1
- sceCdRM freezes when ELF was loaded by certain applications HOT 5
- Timer is not accurate enough.
- USB driver not working well with unaligned content HOT 5
- [System 2x6] default behaviour of `_libcglue_init()` causes system 2x6 to freeze before reaching `main()` HOT 6
- What tool for generating/editing textures?
- Issues compiling the ps2 port of SM64 and the new releases of OPL with the latest release of PS2DEV HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ps2sdk.