Like with ecore\+\_\+main\+\_\+loop\+\_\+thread\+\_\+safe\+\_\+call\+\_\+sync() you can provide a callback to call inline in the mainloop, but this time with ecore\+\_\+main\+\_\+loop\+\_\+thread\+\_\+safe\+\_\+call\+\_\+async() the callback is queued and called asynchronously, without the thread blocking.

The mainloop will call this function when it comes around to its synchronisation point. This acts as a \char`\"{}fire and forget\char`\"{} way of having the mainloop do some work for a thread that has finished processing some data and is read to hand it off to the mainloop and the thread wants to march on and do some more work while the main loop deals with \char`\"{}displaying\char`\"{} the results of the previous calculation.

\hyperlink{efl_thread_4}{E\+F\+L Threading example 4}

\hyperlink{efl_thread_5}{E\+F\+L Threading example 5}

\hyperlink{efl_thread_6}{E\+F\+L Threading example 6}


\begin{DoxyCodeInclude}
\textcolor{comment}{//Compile with:}
\textcolor{comment}{//gcc -o efl\_thread\_3 efl\_thread\_3.c -g `pkg-config --cflags --libs elementary`}
\textcolor{preprocessor}{#include <Elementary.h>}
\textcolor{preprocessor}{#include <pthread.h>}

\textcolor{keyword}{static} Evas\_Object *win = NULL;
\textcolor{keyword}{static} Evas\_Object *rect = NULL;

\textcolor{keyword}{struct }info
\{
   \textcolor{keywordtype}{double} x, y;
\};

\textcolor{keyword}{static} \textcolor{keywordtype}{void} my\_thread\_mainloop\_code(\textcolor{keywordtype}{void} *data);

\textcolor{keyword}{static} pthread\_t thread\_id;

\textcolor{comment}{// BEGIN - code running in my custom pthread instance}
\textcolor{comment}{//}
\textcolor{keyword}{static} \textcolor{keywordtype}{void} *
my\_thread\_run(\textcolor{keywordtype}{void} *arg)
\{
   \textcolor{keywordtype}{double} t = 0.0;

   \textcolor{comment}{// inside the pthread function lets loop forever incrementing a time point}
   \textcolor{keywordflow}{for} (;;)
     \{
        \textcolor{keyword}{struct }info *inf = malloc(\textcolor{keyword}{sizeof}(\textcolor{keyword}{struct} info));

        \textcolor{keywordflow}{if} (inf)
          \{
             inf->x = 200 + (200 * sin(t));
             inf->y = 200 + (200 * cos(t));
             \textcolor{comment}{// now call a function in the mainloop and pass it our allocated}
             \textcolor{comment}{// data that it will free when it gets it}
             ecore\_main\_loop\_thread\_safe\_call\_async
                (my\_thread\_mainloop\_code, inf);
          \}
        \textcolor{comment}{// and sleep and loop}
        usleep(1000);
        t += 0.02;
     \}
   \textcolor{keywordflow}{return} NULL;
\}
\textcolor{comment}{//}
\textcolor{comment}{// END - code running in my custom pthread instance}
\textcolor{keyword}{static} \textcolor{keywordtype}{void}
my\_thread\_new(\textcolor{keywordtype}{void})
\{
   pthread\_attr\_t attr;

   \textcolor{keywordflow}{if} (pthread\_attr\_init(&attr) != 0)
     perror(\textcolor{stringliteral}{"pthread\_attr\_init"});
   \textcolor{keywordflow}{if} (pthread\_create(&thread\_id, &attr, my\_thread\_run, NULL) != 0)
     perror(\textcolor{stringliteral}{"pthread\_create"});
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
my\_thread\_mainloop\_code(\textcolor{keywordtype}{void} *data)
\{
   \textcolor{keyword}{struct }info *inf = data;
   evas\_object\_move(rect, inf->x - 50, inf->y - 50);
   free(inf);
\}

\textcolor{comment}{// on window delete - cancel thread then delete window and exit mainloop}
\textcolor{keyword}{static} \textcolor{keywordtype}{void}
del(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   exit(0);
\}

EAPI\_MAIN \textcolor{keywordtype}{int}
elm\_main(\textcolor{keywordtype}{int} argc, \textcolor{keywordtype}{char} **argv)
\{
   Evas\_Object *o;

   elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);

   win = elm_win_util_standard_add(\textcolor{stringliteral}{"efl-thread-3"}, \textcolor{stringliteral}{"EFL Thread 3"});
   evas\_object\_smart\_callback\_add(win, \textcolor{stringliteral}{"delete,request"}, del, NULL);

   o = evas\_object\_rectangle\_add(evas\_object\_evas\_get(win));
   evas\_object\_color\_set(o, 50, 80, 180, 255);
   evas\_object\_resize(o, 100, 100);
   evas\_object\_show(o);
   rect = o;

   \textcolor{comment}{// create custom thread to do some "work on the side"}
   my\_thread\_new();

   evas\_object\_resize(win, 400, 400);
   evas\_object\_show(win);

   elm_run();

   \textcolor{keywordflow}{return} 0;
\}
ELM_MAIN()
\end{DoxyCodeInclude}
 