Release of G'MIC 3.0

General questions about threading: is it possible to do something more complex like GUI thread & worker threads, trigger events, wait for thread completion etc? Or should we stick to non-dependent threads? How should we use mutex effectively?

The github wiki page about multi-threading looks out of date - it doesn’t mention “double underscore globals” or the mutex command. The example at the end randomly fails with:
G'MIC encountered a fatal error (images (1) and images names (2) have different size)

Edit: also, are changes to double underscore globals instantly visible to all other threads?

That is a bug then :frowning: Just after the 3.0.0 release… it hurts…

It should yes, as these variables are shared between threads.

There’s no zc option for either polygon or ellipse? What I wanted to try is to draw eclipse on different z on a volumetric image. draw() could work as well. This also gives me the idea of ellipsoid(), and cube().

A shame indeed that I only discovered this today! I’ve decided not to do anything complex with threading for now, it would make fixing my own bugs more difficult.

Well, looking at it more closely, I’m not that sure this is a bug, after all :slight_smile:

The fact is, there is a rule that should be written in bold on the wiki page :

A G’MIC pipeline run in a thread should never modify the size of the global image list.

Otherwise, there is a risk that at one particular moment, one thread sees an image list with M images (and M associated names), while another one is removing one (or several images) from the list. Hence the error message you get with the example.

The example is bad, really. In particular, one the thread that is doing this:

-do 300,100 -text[-1] @{com,0}\",\"@{com,1},5,5,13,1,255 -w[-1] -rm[-1] -wait 200 -while 1

It just doesn’t stop creating and removing a temporary image that is put on the list. No surprise that it finally interfere with the other threads.

A probable solution (not tested) would be to isolate this thread in a local environment:

-do str={com,@0}\",\"{com,@1} l[] 300,100 -text[-1] $str,5,5,13,1,255 -w[-1] -rm[-1] endl -wait 200 -while 1

So that the size of the global list is not modified, but only the size of the sub-list associated to the local environment.

EDIT: A “correct” way to write the multi-threaded example at the end of the wiki page:

bug :
  (0,0) nm. com
  parallel "repeat inf =[com] $>,0 wait 200 done",\
           "repeat inf =[com] $>,1 wait 100 done",\
           "do str={com,@0}\",\"{com,@1} l[] 300,100 text $str,5,5,13,1,255 w rm endl wait 200 while 1"