You can use threads with Elementary (and EFL) but you need to be careful to only use eina or eet calls inside a thread.

Other libraries are not totally threadsafe except for some specific ecore calls designed for working from threads like the \mbox{\hyperlink{group__Ecore__Pipe__Group_ga5336bc71e829c391926c26750ae0f407}{ecore\+\_\+pipe\+\_\+write()}} and ecore\+\_\+thread calls.

Below is an example of how to use EFL calls from a native thread you have already created. You have to put the EFL calls inside the critical block between \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga0624ccd91c607ed241f45ac1da8875a6}{ecore\+\_\+thread\+\_\+main\+\_\+loop\+\_\+begin()}} and \mbox{\hyperlink{group__Ecore__Main__Loop__Group_gabd2ff96845800d5fcb7cd2607fffa296}{ecore\+\_\+thread\+\_\+main\+\_\+loop\+\_\+end()}} which ensure you gain a lock on the mainloop. Beware that this requires that the thread WAIT to synchronize with the mainloop at the beginning of the critical section. It is highly suggested you use as few of these in your thread as possible and probably put just a single \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga0624ccd91c607ed241f45ac1da8875a6}{ecore\+\_\+thread\+\_\+main\+\_\+loop\+\_\+begin()}} / \mbox{\hyperlink{group__Ecore__Main__Loop__Group_gabd2ff96845800d5fcb7cd2607fffa296}{ecore\+\_\+thread\+\_\+main\+\_\+loop\+\_\+end()}} section at the end of the threads calculation or work when it is done and would otherwise exit to sit idle.

For a progression of examples that become more complex and show other ways to use threading with EFL, please see\+:

\mbox{\hyperlink{efl_thread_2}{EFL Threading example 2}}

\mbox{\hyperlink{efl_thread_3}{EFL Threading example 3}}

\mbox{\hyperlink{efl_thread_4}{EFL Threading example 4}}

\mbox{\hyperlink{efl_thread_5}{EFL Threading example 5}}

\mbox{\hyperlink{efl_thread_6}{EFL Threading example 6}}


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{comment}{//Compile\ with:}}
\DoxyCodeLine{\textcolor{comment}{//gcc\ -\/o\ efl\_thread\_1\ efl\_thread\_1.c\ -\/g\ `pkg-\/config\ -\/-\/cflags\ -\/-\/libs\ elementary`}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <Elementary.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <pthread.h>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}}\ *win\ =\ NULL;}
\DoxyCodeLine{\textcolor{keyword}{static}\ \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}}\ *rect\ =\ NULL;}
\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{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga0624ccd91c607ed241f45ac1da8875a6}{ecore\_thread\_main\_loop\_begin}}();\ \textcolor{comment}{//\ begin\ critical}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \{\ \textcolor{comment}{//\ indented\ for\ illustration\ of\ "{}critical"{}\ block}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{Evas__Common_8h_a2453e92182bad3b0e0d84e5aff433b07}{Evas\_Coord}}\ x,\ y;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ x\ =\ 200\ +\ (200\ *\ sin(t));}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ y\ =\ 200\ +\ (200\ *\ cos(t));}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Evas__Object__Group_ga335c8ee6eaeaac9710656af4f8b0db91}{evas\_object\_move}}(rect,\ x\ -\/\ 50,\ y\ -\/\ 50);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Ecore__Main__Loop__Group_gabd2ff96845800d5fcb7cd2607fffa296}{ecore\_thread\_main\_loop\_end}}();\ \textcolor{comment}{//\ end\ critical}}
\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{}
\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{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}},\ \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{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{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}}\ *o;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ win\ =\ \mbox{\hyperlink{group__Elm__Win__Group_ga23d9d1ffa0a65a1a1dd482d570db1ba0}{elm\_win\_util\_standard\_add}}(\textcolor{stringliteral}{"{}efl-\/thread-\/1"{}},\ \textcolor{stringliteral}{"{}EFL\ Thread\ 1"{}});}
\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}
 