[PD-dev] s4pd help: portable uid-like thing in C?

Iain Duncan iainduncanlists at gmail.com
Sat Jun 12 23:59:08 CEST 2021


Hi Christof, you are right, it was a bad idea,  but the good news is that
in the hours since I posted that I managed to get it to work properly. It's
been a while since I did data structures manually in C... :-)

I went for maintaining a double-linked list of clock_info structures that
just stores them as they come in. If the interpreter is reset, or object
freed, or we make a cancel-clocks request, that just gets walked with all
clocks unset, freed, and the memory for the clock info nodes freed. In
normal operation, no extra walking needs to happen as the (not cancelled)
callback takes ownership of the pointers and cleans up as part of it's
execution. The implementation could certainly be more elegant, but it seems
to be robust (not sure I even need the double linking, but it helped me
think about it...) I made a fuzzy tester that assaults the object with
variable tempo'd delay requests, requests to cancel 1 delay, and requests
to cancel all, and resets and I can't make it crash anymore, even
recreating the object. Phew!

Thanks for the help everyone. Will post to the list when the next cut is
ready.

iain






On Sat, Jun 12, 2021 at 2:28 PM Christof Ressi <info at christofressi.com>
wrote:

> Hi,
>
> this is a bit of a XY question. The actual problem is about managing
> clocks. Let's see if we can find a proper solution.
>
> I would assume that you are storing the clock(s) alongside the interpreter
> instance. If you restart the interpret, unset the clock(s) with
> clock_unset(). If you free the instance, free the clock(s) with
> clock_free().
>
> If that somehow doesn't work for you, explain the exact problem and show
> the code.
>
> ---
>
> > It doesn't need to be unique across the world, just the local machine
>
> Why would your ID even need to be unique across the whole machine? I think
> it should be enough that it's unique within the app. In that case, you can
> simply use the memory address of the interpreter instance itself. In fact,
> that's how Pd creates the canvas and object IDs for communicating with the
> Tcl/Tk GUI app.
>
> Christof
> On 12.06.2021 18:50, Iain Duncan wrote:
>
> Hi folks, i'm wrestling away with the schedule functions for
> Scheme-for-Pd, and I think I can make things a lot more reliable if I let
> every instantiation (or restart) of the scheme interpreter have a uid of
> some sort so that on a reset we can just ignore clocks running out on a
> previous instance instead of trying to clean them all up with manual memory
> management. (which approach is giving me segfaults because I'm screwing
> something up)
>
> Can anyone tell me what a smart way of getting a unique identifier would
> be? It doesn't need to be unique across the world, just the local machine,
> so something that was seeded from system time would be fine. I'm not a Real
> C Programmer though, so am not clear what options will just work across all
> OS's, without needing to add dependencies.
>
> thanks!
>
>
> _______________________________________________
> Pd-dev mailing listPd-dev at lists.iem.athttps://lists.puredata.info/listinfo/pd-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puredata.info/pipermail/pd-dev/attachments/20210612/2d3dbe23/attachment-0001.htm>


More information about the Pd-dev mailing list