[webkit-dev] Problems with threads and using Javascript

Weber, Bernd BWEBE at dolby.com
Tue Dec 2 18:24:07 PST 2008


Hi,

 

Basically we see that Javascript extensions and pthreads are not working
with Webkit, it results in undefined behavior leading to segfaults.

 

We have our own Javascript extension in GtkLauncher:

static void

winobj_cleared_cb(WebKitWebView * web_view, WebKitWebFrame * web_frame,

                  JSGlobalContextRef context, JSObjectRef object,
gpointer data)

{

    JSStringRef myplugin = JSStringCreateWithUTF8CString("MyPlugin");

    JSObjectSetProperty(context, object, myplugin,

                        JSObjectMakeConstructor(context,

                                                MyPlugin_class(context),

                                                MyPlugin_construct),

                        kJSPropertyAttributeNone, NULL);

    JSStringRelease(myplugin);

    ctx = context;

    obj = object;

}

 

In the plugin code we launch another thread that is supposed to open and
close new webkit windows.

However, whenever it runs into that code it will segfault at some point.
But always at another point of the program, most of the time in the
JavaScript engine, usually hanging at assertions. Sometimes it will
actually open a window, most of the time it will not even get that far.

Here the code that calls JavaScript from within the plugin code:

 

void some_function(void) {

 

    printf("Outside thread\n");

    /*call_js_func(0, NULL);*/

    if(pthread_create(tid,NULL,my_thread,priv_data)){

        log("ERROR: pthread_create failed\n");

        return JSValueMakeBoolean(context, false);

    }

 

}

 

static void * my_thread(void *p)

{

    int i = 1;

    char tmp [63];

 

    printf("In thread\n");

    while(1) {

        printf("In loop: %d\n", i);

        call_js_func(0, NULL);

        if (i == 6) break;

        usleep(20000*1000L);

    }

    printf("Leaving thread\n");

 

    pthread_exit(NULL);

}

 

static void call_js_func(int idx, char *argv)

{

    JSStringRef script;

    char code[MAX_BUF_SIZE];

 

    sprintf(code, "my_window_open();");

    if(ctx && obj) {

        script = JSStringCreateWithUTF8CString(code);

        if(JSCheckScriptSyntax(ctx, script, NULL, 0, NULL))

            JSEvaluateScript(ctx, script, obj, NULL, 1, NULL);

        JSStringRelease(script);

    }

}

 

The Javascript function is just something like:

function my_window_open()

{

    window.open("http://www.google.com",
'window2','resizable=no,location=no,menubar=no,status=no,toolbar=no,scro
llbars=no,left=10,top=10,width=400,height=400');

}

 

So if you go to the function "some_function" and uncomment the
"call_js_func'-call and not spawn the thread, you will see that
everything works. I can open and close windows for as long as I like.
Only if I do it from within the thread it just suddenly stops working.

I know that the above is not giving you all the information needed to
reproduce this problem. I'm rather looking for some input and
suggestions as to why this might be happening.

Some additional information:

We run Webkit r38860, built for GTK on top of X11 running on Linux
(Fedora 9). But I see the same behavior on GTK on top of DirectFB
running on a Linux 2.6.15 kernel on MIPS. I see this problem also on
r36403, which is what we started out with.

Any suggestions are welcome!

 

-Bernd




-----------------------------------------
This message (including any attachments) may contain confidential
information intended for a specific individual and purpose.  If you
are not the intended recipient, delete this message.  If you are
not the intended recipient, disclosing, copying, distributing, or
taking any action based on this message is strictly prohibited.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20081202/0b8de5e5/attachment.html>


More information about the webkit-dev mailing list