On Wed, Dec 15, 2010 at 9:42 AM, Michael Menegakis <arx...@gmail.com> wrote:
> On Wed, Dec 15, 2010 at 1:51 AM, Ben Noordhuis <i...@bnoordhuis.nl> wrote:
>> On Tue, Dec 14, 2010 at 23:45, Michael Menegakis <arx...@gmail.com> wrote:
>>> It's not easy to make something on ioquake3 thread safe. e.g. Whenever
>>> i want to print something from it I completely avoid Com_Printf (since
>>> it's massively thread unsafe recursively) and only write on a mutex
>>> protected 'to print' variable.
>>
>> Pro tip: have your worker thread put strings in a mutex-protected
>> circular buffer or linked list and let the main thread print them.
>>
>> Ideally, worker threads only process data and leave it to the main
>> thread to interpret the results (translation vs printing in this
>> case).
>
> I currently have it on a single char* variable. Surprisingly, this
> 'single element buffer' doesn't fill up easily. Then again, computers
> are fast:)
>
> (Of course, I would replace it with an array of say 4, if it deems necessary).

I should point out that while that may be programmatically safe (the
last just gets erased, it doesn't overflow anything), it may be bad
design especially if one "prints" more than one things in the same
cycle. It is design-safe for a 'google translate' outcome since the
internet is slow but even there, two 'prints' on the same cycle may
make the first one lost.
_______________________________________________
ioquake3 mailing list
ioquake3@lists.ioquake.org
http://lists.ioquake.org/listinfo.cgi/ioquake3-ioquake.org
By sending this message I agree to love ioquake3 and libsdl.

Reply via email to