You can also use the ecore\+\_\+thread infrastructure for compute tasks that don\textquotesingle{}t send feedback as they go -\/ they are one-\/shot compute jobs and when done they will trigger the end callback in the mainloop which is intended to pick up the results and \char`\"{}display them\char`\"{}.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{comment}{//Compile with:}}
\DoxyCodeLine{\textcolor{comment}{//gcc -\/o efl\_thread\_6 efl\_thread\_6.c -\/g `pkg-\/config -\/-\/cflags -\/-\/libs elementary`}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <Elementary.h>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *win = NULL;}
\DoxyCodeLine{\textcolor{keyword}{static} \mbox{\hyperlink{struct__Eina__List}{Eina\_List}} *threads;}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{struct }info}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *obj;}
\DoxyCodeLine{   \textcolor{keywordtype}{int} *pix;}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{comment}{// BEGIN -\/ code running in my custom thread instance}}
\DoxyCodeLine{\textcolor{comment}{//}}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{mandel(\mbox{\hyperlink{group__Ecore__Thread__Group_ga0c2e1f8d562ccf80ecc0009ada72496f}{Ecore\_Thread}} *th, \textcolor{keywordtype}{int} *pix, \textcolor{keywordtype}{int} w, \textcolor{keywordtype}{int} h)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \textcolor{keywordtype}{double} x, xx, y, cx, cy, cox, coy;}
\DoxyCodeLine{   \textcolor{keywordtype}{int} iteration, hx, hy, val, r, g, b, rr, gg, bb;}
\DoxyCodeLine{   \textcolor{keywordtype}{int} itermax = 10000;}
\DoxyCodeLine{   \textcolor{keywordtype}{double} magnify = 0.02;}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{comment}{// this mandel calc is run in the worker threads so it's here. it is}}
\DoxyCodeLine{   \textcolor{comment}{// just here to calculate something and consume cpu to demonstrate the}}
\DoxyCodeLine{   \textcolor{comment}{// ecore thread worker queue. don't pay much attention to the below code}}
\DoxyCodeLine{   magnify += ((double)(rand() \% 100) / 100.0) / 4.0;}
\DoxyCodeLine{   cox = (double)(rand() \% 100) / 100.0;}
\DoxyCodeLine{   coy = (double)(rand() \% 100) / 100.0;}
\DoxyCodeLine{   cox /= (magnify * 3.0);}
\DoxyCodeLine{   r = rand() \% 255; g = rand() \% 255; b = rand() \% 255;}
\DoxyCodeLine{   \textcolor{keywordflow}{for} (hy = 0; hy < h; hy++)}
\DoxyCodeLine{     \{}
\DoxyCodeLine{        \textcolor{comment}{// every line check if thread has been cancelled to return early}}
\DoxyCodeLine{        \textcolor{keywordflow}{if} (\mbox{\hyperlink{group__Ecore__Thread__Group_ga792471a7ed00718b71d58b791ddbd08d}{ecore\_thread\_check}}(th)) \textcolor{keywordflow}{return};}
\DoxyCodeLine{        \textcolor{keywordflow}{for} (hx = 0; hx < w; hx++)}
\DoxyCodeLine{          \{}
\DoxyCodeLine{             cx = (((float)hx) / ((float)w) -\/ 0.5) / (magnify * 3.0);}
\DoxyCodeLine{             cy = (((float)hy) / ((float)h) -\/ 0.5) / (magnify * 3.0);}
\DoxyCodeLine{             cx += cox;}
\DoxyCodeLine{             cy += coy;}
\DoxyCodeLine{             x = 0.0;}
\DoxyCodeLine{             y = 0.0;}
\DoxyCodeLine{             \textcolor{keywordflow}{for} (iteration = 1; iteration < itermax; iteration++)}
\DoxyCodeLine{               \{}
\DoxyCodeLine{                  xx = (x * x) -\/ (y * y) + cx;}
\DoxyCodeLine{                  y = (2.0 * x * y) + cy;}
\DoxyCodeLine{                  x = xx;}
\DoxyCodeLine{                  \textcolor{keywordflow}{if} (((x * x) + (y * y)) > 100.0) iteration = 999999;}
\DoxyCodeLine{               \}}
\DoxyCodeLine{             val = (((x * x) + (y * y)) * 2.55) / 100.0;}
\DoxyCodeLine{             \textcolor{keywordflow}{if} (val > 255) val = 255;}
\DoxyCodeLine{             \textcolor{keywordflow}{if} (iteration >= 99999)}
\DoxyCodeLine{               \{}
\DoxyCodeLine{                  rr = (r * val) / 255;}
\DoxyCodeLine{                  gg = (g * val) / 255;}
\DoxyCodeLine{                  bb = (b * val) / 255;}
\DoxyCodeLine{                  pix[(hy * w) + hx] =}
\DoxyCodeLine{                     (val  << 24) | (rr << 16) | (gg << 8) | (bb);}
\DoxyCodeLine{               \}}
\DoxyCodeLine{             \textcolor{keywordflow}{else}}
\DoxyCodeLine{               pix[(hy * w) + hx] = 0xffffffff;}
\DoxyCodeLine{          \}}
\DoxyCodeLine{     \}}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{th\_do(\textcolor{keywordtype}{void} *data, \mbox{\hyperlink{group__Ecore__Thread__Group_ga0c2e1f8d562ccf80ecc0009ada72496f}{Ecore\_Thread}} *th)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \textcolor{keyword}{struct }info *inf = data;}
\DoxyCodeLine{   \textcolor{comment}{// CANNOT TOUCH inf-\/>obj here! just inf-\/>pix which is 256x256 @ 32bpp}}
\DoxyCodeLine{   \textcolor{comment}{// quick and dirty to consume some cpu -\/ do a mandelbrot calc}}
\DoxyCodeLine{   mandel(th, inf-\/>pix, 256, 256);}
\DoxyCodeLine{\}}
\DoxyCodeLine{\textcolor{comment}{//}}
\DoxyCodeLine{\textcolor{comment}{// END -\/ code running in my custom thread instance}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{void} \textcolor{comment}{// thread job finished -\/ collect results and put in img obj}}
\DoxyCodeLine{th\_end(\textcolor{keywordtype}{void} *data, \mbox{\hyperlink{group__Ecore__Thread__Group_ga0c2e1f8d562ccf80ecc0009ada72496f}{Ecore\_Thread}} *th)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \textcolor{keyword}{struct }info *inf = data;}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{comment}{// copy data to object, free calculated data and info struc}}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Image_ga7ba2a93c93e07b30d3dfc197ffe7ce85}{evas\_object\_image\_data\_copy\_set}}(inf-\/>obj, inf-\/>pix);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}}(inf-\/>obj);}
\DoxyCodeLine{   free(inf-\/>pix);}
\DoxyCodeLine{   free(inf);}
\DoxyCodeLine{   threads = \mbox{\hyperlink{group__Eina__List__Group_ga7c0c6e07aa592a1cb2e010049a718035}{eina\_list\_remove}}(threads, th);}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{void} \textcolor{comment}{// if the thread is cancelled -\/ free pix, keep obj tho}}
\DoxyCodeLine{th\_cancel(\textcolor{keywordtype}{void} *data, \mbox{\hyperlink{group__Ecore__Thread__Group_ga0c2e1f8d562ccf80ecc0009ada72496f}{Ecore\_Thread}} *th \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \textcolor{keyword}{struct }info *inf = data;}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{comment}{// just free pixel data and info struct}}
\DoxyCodeLine{   free(inf-\/>pix);}
\DoxyCodeLine{   free(inf);}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}} \textcolor{comment}{// animate the objects so you see all the madels move}}
\DoxyCodeLine{anim(\textcolor{keywordtype}{void} *data)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *o = data;}
\DoxyCodeLine{   \textcolor{keywordtype}{double} t, z;}
\DoxyCodeLine{   \textcolor{keywordtype}{int} w, h, v;}
\DoxyCodeLine{   \mbox{\hyperlink{Evas__Common_8h_a2453e92182bad3b0e0d84e5aff433b07}{Evas\_Coord}} x, y;}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{comment}{// just calculate some position using the pointer value of the object as}}
\DoxyCodeLine{   \textcolor{comment}{// a seed value to make different objects go into different places over time}}
\DoxyCodeLine{   v = ((int)(uintptr\_t)o) \& 0xff;}
\DoxyCodeLine{   t = \mbox{\hyperlink{group__Ecore__Time__Group_gab53d952cc4c2f3ed032d535b307c43bd}{ecore\_loop\_time\_get}}();}
\DoxyCodeLine{   w = 100 + ((v * 100) >> 8);}
\DoxyCodeLine{   h = 100 + ((v * 100) >> 8);}
\DoxyCodeLine{   z = (double)(v) / 100.0;}
\DoxyCodeLine{   x = (w * sin(t));}
\DoxyCodeLine{   y = (h * cos(t + z));}
\DoxyCodeLine{   \textcolor{comment}{// do the actual move}}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group_ga02da8091bbac768b8e86c7b74b2a94f9}{evas\_object\_move}}(o, 200 + x -\/ 128, 200 + y -\/ 128);}
\DoxyCodeLine{   \textcolor{comment}{// keep looping -\/ return true}}
\DoxyCodeLine{   \textcolor{keywordflow}{return} \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}};}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{EAPI\_MAIN \textcolor{keywordtype}{int}}
\DoxyCodeLine{elm\_main(\textcolor{keywordtype}{int} argc \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \textcolor{keywordtype}{char} **argv \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *o;}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Thread__Group_ga0c2e1f8d562ccf80ecc0009ada72496f}{Ecore\_Thread}} *th;}
\DoxyCodeLine{   \textcolor{keywordtype}{int} i;}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__General_ga7a05f37fd3a019da5e26c5fc91fcd937}{elm\_policy\_set}}(\mbox{\hyperlink{group__Elm__General_ggaa16f3378ecdbf660fa378402e3c5a0a9a02fadb6faada04b19d0fa42c11a8d32a}{ELM\_POLICY\_QUIT}}, \mbox{\hyperlink{group__Elm__General_gga46af37e6ac2c406321060be827117196abbe0962d88ae12afe1a173da881f56cd}{ELM\_POLICY\_QUIT\_LAST\_WINDOW\_CLOSED}});}
\DoxyCodeLine{}
\DoxyCodeLine{   win = \mbox{\hyperlink{group__Elm__Win__Group_gac75d7752662fab73d6420706ce5be996}{elm\_win\_util\_standard\_add}}(\textcolor{stringliteral}{"{}efl-\/thread-\/6"{}}, \textcolor{stringliteral}{"{}EFL Thread 6"{}});}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__Win__Group_ga9a16a2f8c9fd5b6e9203ed9dcb53ea8b}{elm\_win\_autodel\_set}}(win, \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}});}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{comment}{// queue up 64 mandel generation thread jobs}}
\DoxyCodeLine{   \textcolor{keywordflow}{for} (i = 0; i < 64; i++)}
\DoxyCodeLine{     \{}
\DoxyCodeLine{        \textcolor{keyword}{struct }info *inf;}
\DoxyCodeLine{}
\DoxyCodeLine{        \textcolor{comment}{// create ecore thread to do some threaded job inside the worker pool}}
\DoxyCodeLine{        inf = malloc(\textcolor{keyword}{sizeof}(\textcolor{keyword}{struct} info));}
\DoxyCodeLine{        \textcolor{keywordflow}{if} (inf)}
\DoxyCodeLine{          \{}
\DoxyCodeLine{             o = \mbox{\hyperlink{group__Evas__Object__Image_ga0e8cb83d31d02bf583c75925b7cd14d7}{evas\_object\_image\_filled\_add}}(\mbox{\hyperlink{group__Evas__Object__Group_gae1058082dae7b97590c41f43405dfdbf}{evas\_object\_evas\_get}}(win));}
\DoxyCodeLine{             \mbox{\hyperlink{group__Evas__Object__Image_ga369c3638028094b1d66bd482778eb6b2}{evas\_object\_image\_size\_set}}(o, 256, 256);}
\DoxyCodeLine{             \mbox{\hyperlink{group__Evas__Object__Image_ga325eaa4977ef66b8a0cd5de1a221cb26}{evas\_object\_image\_alpha\_set}}(o, \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}});}
\DoxyCodeLine{             \mbox{\hyperlink{group__Evas__Object__Group_ga21e8604c0e4a93e469bff4bd069e82b5}{evas\_object\_resize}}(o, 256, 256);}
\DoxyCodeLine{             inf-\/>obj = o;}
\DoxyCodeLine{             inf-\/>pix = malloc(256 * 256 * \textcolor{keyword}{sizeof}(\textcolor{keywordtype}{int}));}
\DoxyCodeLine{             th = \mbox{\hyperlink{group__Ecore__Thread__Group_gaac9c9933ef0a90ba86f8fd0247e9c7ef}{ecore\_thread\_run}}(th\_do, th\_end, th\_cancel, inf);}
\DoxyCodeLine{             threads = \mbox{\hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}}(threads, th);}
\DoxyCodeLine{             \textcolor{comment}{// bonus -\/ slide the objects around all the time with an}}
\DoxyCodeLine{             \textcolor{comment}{// animator that ticks off every frame.}}
\DoxyCodeLine{             \mbox{\hyperlink{group__Ecore__Animator__Group_gaa1e33b8be9117a26918823c535e429ea}{ecore\_animator\_add}}(anim, o);}
\DoxyCodeLine{          \}}
\DoxyCodeLine{     \}}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group_ga21e8604c0e4a93e469bff4bd069e82b5}{evas\_object\_resize}}(win, 400, 400);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}}(win);}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__General_gadf2553f83e6b0b9c7fbe054019a664a1}{elm\_run}}();}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{comment}{// if some threads are still running -\/ cancel them}}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eina__List__Group_gae27a2c686a0a11693f9b06957c9bba83}{EINA\_LIST\_FREE}}(threads, th) \mbox{\hyperlink{group__Ecore__Thread__Group_gae9b9b20e1ed53c62c51617b55aed2511}{ecore\_thread\_cancel}}(th);}
\DoxyCodeLine{}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} 0;}
\DoxyCodeLine{\}}
\DoxyCodeLine{\mbox{\hyperlink{group__Elm__General_ga50fe52d513f7e89c9c770afd76de7ad9}{ELM\_MAIN}}()}

\end{DoxyCodeInclude}
 