On 07/29/2011 05:56 PM, Cedric BAIL wrote:

> Then take that pseudo example :
> 
> Eina_Bool _timer_in_main_loop(void *data)
> {
>    ....;
     lock_data_mutex();
     if (!data_was_deleted)
       {
>        free(data);
       }
     data_was_deleted = Eina_True;
     unlock_data_mutex();
>    return 0;
> }
> 
> void bad_idea()
> {
>    tuttut = ecore_timer_add(unlucky, _timer_in_main_loop, something);
>    ...;
> 
>    if (bad_happen)
>       {
          lock_data_mutex();
          if (!data_was_deleted)
            {
>             ecore_timer_del(tuttut);
>             free(something);
            }
          data_was_deleted = Eina_True;
          unlock_data_mutex();
>       }
> }
> 
> This code will work just fine in the main loop. Now in a thread it's
> full of race condition and double free. Tell me how you can make it
> work ? 

Add a mutex. See above.

Nobody said threaded programming is easy.  I'm just adding one tool.
Maybe you don't want to use this tool, that's OK.  Maybe you want to
provide a different way to do it, that's OK too.  Maybe you want to
make a law against using threads with ecore in EFL code, that's OK too.
Saying the tool itself is bad is a non-started, IMO.

The fact is, people already write this kind of racy code.  They think
it works, and when it crashes in ecore, EFL gets the blame.

So you can stand stubbornly refuse to fix it, or move the problem to 
their code, so it will crash outside of ecore, and people will not
blame EFL.

Additionally, people who grok threads well (admittedly not many)
can write code that works with ecore main loop.

Support choice, and suggest the best way.

>    As far as I know, Cocoa, GTK, Qt and Win32 are not thread safe, and
> nobody complain about that. 

I know Win32's main loop is thread safe.

thanks,

Mike

------------------------------------------------------------------------------
Got Input?   Slashdot Needs You.
Take our quick survey online.  Come on, we don't ask for help often.
Plus, you'll get a chance to win $100 to spend on ThinkGeek.
http://p.sf.net/sfu/slashdot-survey
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to