Tim Lambert wrote: > > I'm writing a plugin in a mixture of Scheme and C. The problem I'm > having is that when I call the Scheme code from C (using > gimp_run_procedure2 after registering the script with > script-fu-register), gimp_run_procedure2 returns immediately and the > script runs in another thread. > > I'd like to wait until the script finishes before doing anything > else. Gimp doesn't seem to be thread safe, so about half the time the > plugin will crash or show the wrong data. Even if gimp was thread > safe I would still want to wait, but the result would be confusing > rather than catastrophic. > I don't think there is a good way to do this, but there is a hack that should work. You can use a parasite as a mutex lock because calls to the parasite functions are atomic. C code should look something like this: gimp_image_parasite_detach(imageID, "myplugin-mutexlock"); /* in case it is left over from a previous call */ gimp_run_procedure2(....); while (!(p = gimp_image_parasite_find(imageID, "myplugin-mutexlock")) usleep(500); gimp_parasite_free(p); gimp_image_parasite_detach(imageID, "myplugin-mutexlock"); /* clean up parasite */ <rest of plugin goes here> In your scheme function you will want to add a parasite to the image with the name "myplugin-mutexlock" as the last statement in the script. Of course if your script-fu bombs out your plugin will never return. Hope This helps, Jay Cox jaycox@xxxxxxxx