aconstlink / motor

Software Framework for Audio/Visual/Interactive Real-Time Applications
MIT License
1 stars 0 forks source link

Ownership model needs refactoring #44

Closed aconstlink closed 4 months ago

aconstlink commented 5 months ago

I thought to loosen the explicit memory management. But it turned out, it is not working as expected for multi-threaded scenarios.

At the moment, only unique managed pointers are working correctly by holding the ref count before passing the pointer. Shared pointers do not do that and are exposed to access a dangling pointer if the creator happened to release the resource after passing it.

The whole shared idea is completely useless and out of function at the moment.

Therefore. Passing managed pointers need two ways only to be handled:

First: How to pass on the resource

// increment ref count ( copy pointer )
motor::share( mtr ) ;
// take ref count ( move pointer )
motor::unique( mtr ) ;

Second: What is the intention

// allows to freely pass around the pointer (borrowing)
some_funk( any_mtr_t ) 
{
    // use pointer
}

// requires the pointer to be copied or moved. Also requires
// a release of the pointer.
some_funk( any_mtr_safe_t ptr )
{
    // use or store pointer but requires a ...
    motor::memory::release_ptr( ptr ) ;
    // somewhere in the code of the receiver
}

So

This all also means, that a stored _mtr_t pointer hides the intention of being shared or unique. But I didn't really ever used this idea when storing the pointer. The point here is that, shared or unique, the managed pointer needs to be released.