From owner-freebsd-current@FreeBSD.ORG Sat Nov 24 14:50:59 2007 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 97A9616A417 for ; Sat, 24 Nov 2007 14:50:59 +0000 (UTC) (envelope-from c47g@gmx.at) Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by mx1.freebsd.org (Postfix) with SMTP id 18EA213C47E for ; Sat, 24 Nov 2007 14:50:58 +0000 (UTC) (envelope-from c47g@gmx.at) Received: (qmail invoked by alias); 24 Nov 2007 14:24:11 -0000 Received: from d91-128-253-18.cust.tele2.at (EHLO bones) [91.128.253.18] by mail.gmx.net (mp051) with SMTP; 24 Nov 2007 15:24:11 +0100 X-Authenticated: #9978462 X-Provags-ID: V01U2FsdGVkX1+o+LJRpgeo/LTEtRKzybdLURSYLBccdCcpJqkd8l ieU8YZOo6DuRP8 From: Christian Gusenbauer To: freebsd-current@freebsd.org Date: Sat, 24 Nov 2007 15:25:05 +0100 User-Agent: KMail/1.9.7 MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart1208871.ufsJEfDTOy"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit Message-Id: <200711241525.10171.c47g@gmx.at> X-Y-GMX-Trusted: 0 Subject: Crashes with SDL and libthr X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 Nov 2007 14:50:59 -0000 --nextPart1208871.ufsJEfDTOy Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi! I've just updated to today's current and now some SDL based applications ar= e=20 crashing. I debugged a bit and found out, that the changes made to libthr a= re=20 causing these crashes. The attached program crashes immediately using the=20 current libthr. This program does not crash when I'm using an old version o= f=20 libthr (before 2007/11/21). /* compiled with: cc -g -I/usr/local/include -L/usr/local/lib sdltest.c -lSDL -lthr -o sdltest */ #include #include #include #include #define SAMPLE_FREQ 44100 #define SAMPLE_SIZE (512*2) void AudioCallbackSDL(void *udata, u_int8_t *buffer, int length) { } main() { SDL_AudioSpec audioSpec; SDL_AudioSpec mySpec; if (SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_AUDIO ) < 0) { fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); exit(1); } memset((void*)&audioSpec, 0, sizeof(SDL_AudioSpec)); memset((void*)&mySpec, 0, sizeof(SDL_AudioSpec)); audioSpec.freq =3D SAMPLE_FREQ; audioSpec.format =3D AUDIO_U8; audioSpec.channels =3D 1; audioSpec.samples =3D SAMPLE_SIZE/(44100/SAMPLE_FREQ); audioSpec.callback =3D AudioCallbackSDL; audioSpec.userdata =3D (void*)1; if (SDL_OpenAudio(&audioSpec, &mySpec) < 0) { fprintf(stderr, "can't open SDL audio: %s\n", SDL_GetError()); exit(1); } sleep(10); } =2D------------------------------------------------------------------------= =2D- I debugged SDL and found the following piece of code, which causes the crash in SDL_thread.c (around line 249). args->func =3D fn; args->data =3D data; args->info =3D thread; args->wait =3D SDL_CreateSemaphore(0); ^ + here a semaphore is created with initial value 0 if ( args->wait =3D=3D NULL ) { SDL_free(thread); SDL_free(args); return(NULL); } /* Add the thread to the list of available threads */ SDL_AddThread(thread); /* Create the thread and go! */ #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD ret =3D SDL_SYS_CreateThread(thread, args, pfnBeginThread,=20 pfnEndThread); #else ret =3D SDL_SYS_CreateThread(thread, args); #endif if ( ret >=3D 0 ) { /* Wait for the thread function to use arguments */ SDL_SemWait(args->wait); ^ + here the calling thread should wait for the newly created thread (but it doesn't) } else { /* Oops, failed. Gotta free everything */ SDL_DelThread(thread); SDL_free(thread); thread =3D NULL; } SDL_DestroySemaphore(args->wait); SDL_free(args); ^ + here the args are freed, which causes the crash of the newly created thread. So I assume something's wrong with the semaphore operations The newly created thread crashes, because he uses the args area passed as=20 parameter to the SDL_SYS_CreateThread call and the parent thread is not=20 waiting as it is supposed to. Could someone please have a look at these libthr changes? Many thanks, Christian. --nextPart1208871.ufsJEfDTOy Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.4 (FreeBSD) iD8DBQBHSDRG73Wh/GTgh8wRAq+iAJ43bWwFOjMfd9OSQYjLMAptOkEvRgCfQbUS hh7ue8U9MMp3ME73lHwf0I0= =acqz -----END PGP SIGNATURE----- --nextPart1208871.ufsJEfDTOy--