Multitasking question: Making a picture viewer, loading lots of images in the background

realhet real_het at hotmail.com
Wed Apr 3 02:59:51 UTC 2019


Hi,

I'm writing a picture browser program and I'd like to ask for a 
bit of assistance.

My app is basically a Win32 window with an OpenGL surface. 
Currently I'm able to display a lot of pictures in it. The 
decompression of the bitmaps take place at the beginning of the 
program.

I want to make this more user friendly, so at first I only draw 
placeholders for the pictures while the actual loading and 
decompression is happening on worker threads.

I used std.concurrency.spawn. The parameters are the filename, 
and an index. After the decompression I let the main thread know 
about there is a bitmap it should upload to a texture later. I do 
it using synchronize, it works without error and was really easy 
to implements in D.

My problem is that when I launch 1000 spawn(), the work overload 
on the main thread is so heavy that the 60FPS timer which is 
refreshing the windows never can be called. Obviously spawn() is 
not the right choice for this.

In my previous projects I addressed this by creating 
NumberOfProcessorThreads threads,and locked them on specific 
ProcessorThreads by using ProcessAffinity, so the main thread has 
enough time to generate fluid user interface while the other 
worker threads used 100%CPU for the fastest processing.

I also remember that with OPENMP I was also able to lock workers 
onto specific ProcessorThreads, it also worked fine.

But how can I do this elegantly in D?

Thanks in advance!


(Also I'm not sure how spaw()-n is working exactly. Is it creates 
a new process for every spawn() call, or is it assigns the task 
to one of the N worker processes? 1000 CreateProcess() api calls 
would be not so nice. I just wanna know it in order to avoid it.)


More information about the Digitalmars-d-learn mailing list