[webkit-dev] Problems with threads and using Javascript

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



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,




                        kJSPropertyAttributeNone, NULL);


    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);*/


        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;



    printf("Leaving thread\n");





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);





The Javascript function is just something like:

function my_window_open()





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!



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