Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing threads, how should I deal with something which ideally should happen in sequential order?
    primarykey
    data
    text
    <p>I have an image generator which would benefit from running in threads. I am intending to use POSIX threads, and have written some mock up code based on <a href="https://computing.llnl.gov/tutorials/pthreads/#ConVarSignal" rel="nofollow noreferrer">https://computing.llnl.gov/tutorials/pthreads/#ConVarSignal</a> to test things out.</p> <p>In the intended program, when the GUI is in use, I want the generated lines to appear from the top to the bottom one by one (the image generation can be very slow).</p> <p>It should also be noted, the data generated in the threads is not the actual image data. The thread data is read and transformed into RGB data and placed into the actual image buffer. And within the GUI, the way the thread generated data is translated to RGB data can be changed during image generation without stopping image generation. </p> <p>However, there is no guarantee from the thread scheduler that the threads will run in the order I want, which unfortunately makes the transformations of the thread generated data trickier, implying the undesirable solution of keeping an array to hold a bool value to indicate which lines are done.</p> <p>How should I deal with this?</p> <p>Currently I have a watcher thread to report when the image is complete (which really should be for a progress bar but I've not got that far yet, it instead uses <code>pthread_cond_wait</code>). And several render threads doing <code>while(next_line());</code></p> <p><code>next_line()</code> does a mutex lock, and gets the value of img_next_line before incrementing it and unlocking the mutex. it then renders the line and does a mutex lock (different to first) to get lines_done checks against height, signals if complete, unlocks and returns 0 if complete or 1 if not.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload