Open Woyten opened 6 years ago
Your remarks are relevant. Have you the time to implement them?
Yes, I can do it. In my opinion, there is not much that needs to be done. However, there will be some impact on the existing examples and tests. I think, some Arc
and Mutex
wrappers (Don't know the mutability by heart) will be necessary.
Hmm... Sync
and Send
usually are auto-derived. They should only be implemented manually if they are safe to be used in different threads.
An example: In the current setup, OutputPort
is Send
. You can create as many instances as you want and send them to different threads. This means all functions like write_message
, etc. can be executed concurrently. I am not sure if the underlying ffi::Pm_WriteShort
is actually thread-safe.
If the merged pull request resolve the issue, please close it and create a new release.
It doesn't solve all the pb but I'll do a release to have the lifetime update.
I do the cargo publish of the version 0.2.5
This example segfaults:
The problem is that
output_port
outlivescontext
. To be more precise,context
callsPm_Terminate
in its destructor renderingoutput_port
invalid. But, unfortunately,outport_port
is still accessible after the scope braces. The problem can be solved by adding an artificial lifetime to theDeviceInfo
struct, s.t. Rust knows thatoutput_port
depends on aDeviceInfo
instance which depends oncontext
. Also,DeviceInfo::new
should be unsafe andPortMidi::device
should validate the device number.