Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To reduce number of mutexes:-</p> <ul> <li><p>Have one mutex for access to a bit buffer of lines signalled as done (8000/8bits = 1000byte buffer).</p></li> <li><p>A second temporary bit buffer.</p></li> <li><p>Worker thread locks mutex, sets bit in first buffer and unlocks mutex.</p></li> <li><p>Main loop locks mutex, copies first buffer to second and unlocks mutex.</p></li> <li><p>Then scans second buffer for non-zero, and for each set bit, copies data for that line to output / screen.</p></li> <li><p>To reduce the contention on the first bit buffer you could partition the first bit buffer into 8 or even 16 segments (which segment to look in us based on the line number mod 8 or mod 16) and have a mutex for each segment.</p></li> </ul> <p>--</p> <p>Probably the way to go is to use the design I was suggesting but "try_lock" (rather than wait for) the locks, do a couple of NOPs and retry until they become available rather than yielding. It may be worth using atomic inc/dec directly rather than pthread mutexes for higher performance.</p> <p>Finally it is not worth having 8 threads unless you have 8 processors, and I don't know about get_time_of_day.</p> <p><strong>Edit</strong>: There is perhaps a flaw with what I suggest that if the main thread is preempted whilst it has locked a bit buffer mutex, that the other threads waste a load of time. The frequency of this happening might be reduced by lowering the priorioty of the other threads but I think a better overall strategy is to use an array of 8000 atomic_t types with the atomic inc/dec instructions to signal line completion from worker threads to main thread. These 8000 atomic_t's can be searched by the main thread. I kind of assumed too that you'd reduce the number of worker threads to be one less than the number of CPUs.</p> <p><strong>Edit</strong>: Eight threads seems a bit arbitrary. Where did you get this number from? Obviously you need at least one worker thread.</p> <p><strong>Edit</strong>: Even faster would be to use atomic_set_mask to set bits in a 1000 byte buffer that the front end scans in a loop.</p> <p><strong>Edit</strong>: Assuming you have atomic_set_mask on your platform.</p>
    singulars
    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.
    1. This table or related slice is empty.
    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