\chapter{EFL Threading example 2}
\hypertarget{efl_thread_2}{}\label{efl_thread_2}\index{EFL Threading example 2@{EFL Threading example 2}}
You can also use \doxylink{group__Ecore__Main__Loop__Group_ga92dd9de1e09a667b96c94d02e3d61c06}{ecore\+\_\+main\+\_\+loop\+\_\+thread\+\_\+safe\+\_\+call\+\_\+sync()} to call a specific function that needs to do EFL main loop operations. This call will block and wait to synchronise to the mainloop just like \doxylink{group__Ecore__Main__Loop__Group_ga0624ccd91c607ed241f45ac1da8875a6}{ecore\+\_\+thread\+\_\+main\+\_\+loop\+\_\+begin()} / \doxylink{group__Ecore__Main__Loop__Group_gabd2ff96845800d5fcb7cd2607fffa296}{ecore\+\_\+thread\+\_\+main\+\_\+loop\+\_\+end()} will, but instead you simply provide it the function callback to call instead of inlining your code.

\doxysectlink{efl_thread_3}{EFL Threading example 3}{0}

\doxysectlink{efl_thread_4}{EFL Threading example 4}{0}

\doxysectlink{efl_thread_5}{EFL Threading example 5}{0}

\doxysectlink{efl_thread_6}{EFL Threading example 6}{0}


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{comment}{//Compile\ with:}}
\DoxyCodeLine{\textcolor{comment}{//gcc\ -\/o\ efl\_thread\_2\ efl\_thread\_2.c\ -\/g\ \`{}pkg-\/config\ -\/-\/cflags\ -\/-\/libs\ elementary`}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <Elementary.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <pthread.h>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ Evas\_Object\ *win\ =\ NULL;}
\DoxyCodeLine{\textcolor{keyword}{static}\ Evas\_Object\ *rect\ =\ NULL;}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{struct\ }info}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{double}\ x,\ y;}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}\ *my\_thread\_mainloop\_code(\textcolor{keywordtype}{void}\ *data);}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ pthread\_t\ thread\_id;}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{comment}{//\ BEGIN\ -\/\ code\ running\ in\ my\ custom\ pthread\ instance}}
\DoxyCodeLine{\textcolor{comment}{//}}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}\ *}
\DoxyCodeLine{my\_thread\_run(\textcolor{keywordtype}{void}\ *arg\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{double}\ t\ =\ 0.0;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{for}\ (;;)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keyword}{struct\ }info\ *inf\ =\ malloc(\textcolor{keyword}{sizeof}(\textcolor{keyword}{struct}\ info));}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (inf)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ inf-\/>x\ =\ 200\ +\ (200\ *\ sin(t));}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ inf-\/>y\ =\ 200\ +\ (200\ *\ cos(t));}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga92dd9de1e09a667b96c94d02e3d61c06}{ecore\_main\_loop\_thread\_safe\_call\_sync}}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (my\_thread\_mainloop\_code,\ inf);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{comment}{//\ and\ sleep\ and\ loop}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ usleep(1000);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ t\ +=\ 0.02;}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{\}}
\DoxyCodeLine{\textcolor{comment}{//}}
\DoxyCodeLine{\textcolor{comment}{//\ END\ -\/\ code\ running\ in\ my\ custom\ pthread\ instance}}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{my\_thread\_new(\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ pthread\_attr\_t\ attr;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (pthread\_attr\_init(\&attr)\ !=\ 0)}
\DoxyCodeLine{\ \ \ \ \ perror(\textcolor{stringliteral}{"{}pthread\_attr\_init"{}});}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (pthread\_create(\&thread\_id,\ \&attr,\ my\_thread\_run,\ NULL)\ !=\ 0)}
\DoxyCodeLine{\ \ \ \ \ perror(\textcolor{stringliteral}{"{}pthread\_create"{}});}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}\ *}
\DoxyCodeLine{my\_thread\_mainloop\_code(\textcolor{keywordtype}{void}\ *data)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{keyword}{struct\ }info\ *inf\ =\ data;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_ga335c8ee6eaeaac9710656af4f8b0db91}{evas\_object\_move}}(rect,\ inf-\/>x\ -\/\ 50,\ inf-\/>y\ -\/\ 50);}
\DoxyCodeLine{\ \ \ free(inf);}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{comment}{//\ on\ window\ delete\ -\/\ cancel\ thread\ then\ delete\ window\ and\ exit\ mainloop}}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{del(\textcolor{keywordtype}{void}\ *data\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}},\ Evas\_Object\ *obj\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}},\ \textcolor{keywordtype}{void}\ *event\_info\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ exit(0);}
\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{\ \ \ Evas\_Object\ *o;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ win\ =\ \mbox{\hyperlink{group__Elm__Win__Group_ga23d9d1ffa0a65a1a1dd482d570db1ba0}{elm\_win\_util\_standard\_add}}(\textcolor{stringliteral}{"{}efl-\/thread-\/2"{}},\ \textcolor{stringliteral}{"{}EFL\ Thread\ 2"{}});}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Smart__Object__Group_gac12dd6655f488cc47ce6cf00eb7d12b2}{evas\_object\_smart\_callback\_add}}(win,\ \textcolor{stringliteral}{"{}delete,request"{}},\ del,\ NULL);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ o\ =\ \mbox{\hyperlink{group__Evas__Object__Rectangle_ga1b7a9d8e6ce240590c1734da5f3449d2}{evas\_object\_rectangle\_add}}(\mbox{\hyperlink{group__Evas__Object__Group_ga7e211219d11abced5f3089362f7476b9}{evas\_object\_evas\_get}}(win));}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_gab751e9d24c16e74af6f7c08ea5b930c2}{evas\_object\_color\_set}}(o,\ 50,\ 80,\ 180,\ 255);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_gacad94595f83580c18908cb3b69b08d1a}{evas\_object\_resize}}(o,\ 100,\ 100);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga07208fcafd4739de606bc35fff684bf5}{evas\_object\_show}}(o);}
\DoxyCodeLine{\ \ \ rect\ =\ o;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{//\ create\ custom\ thread\ to\ do\ some\ "{}work\ on\ the\ side"{}}}
\DoxyCodeLine{\ \ \ my\_thread\_new();}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_gacad94595f83580c18908cb3b69b08d1a}{evas\_object\_resize}}(win,\ 400,\ 400);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga07208fcafd4739de606bc35fff684bf5}{evas\_object\_show}}(win);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__General_gadf2553f83e6b0b9c7fbe054019a664a1}{elm\_run}}();}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{\}}
\DoxyCodeLine{\mbox{\hyperlink{group__Elm__General_ga50fe52d513f7e89c9c770afd76de7ad9}{ELM\_MAIN}}()}

\end{DoxyCodeInclude}
 