X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fnasal%2Fthreadlib.c;h=d5e51ef662a2c7c537596ec05842230a196930aa;hb=66193d728365098783e56a292541f01e9a4c57ca;hp=eda7f234893075788742253f7da2507702f1f086;hpb=b05e32fa8c11e6d66bb70850751e170dc472a1a3;p=simgear.git diff --git a/simgear/nasal/threadlib.c b/simgear/nasal/threadlib.c index eda7f234..d5e51ef6 100644 --- a/simgear/nasal/threadlib.c +++ b/simgear/nasal/threadlib.c @@ -1,3 +1,4 @@ +#include #ifdef _WIN32 #include #else @@ -43,7 +44,12 @@ static naRef f_newthread(naContext c, naRef me, int argc, naRef* args) #ifdef _WIN32 CreateThread(0, 0, threadtop, td, 0, 0); #else - { pthread_t t; pthread_create(&t, 0, threadtop, td); } + { + pthread_t t; int err; + if((err = pthread_create(&t, 0, threadtop, td))) + naRuntimeError(c, "newthread failed: %s", strerror(err)); + pthread_detach(t); + } #endif return naNil(); } @@ -55,8 +61,11 @@ static naRef f_newlock(naContext c, naRef me, int argc, naRef* args) static naRef f_lock(naContext c, naRef me, int argc, naRef* args) { - if(argc > 0 && naGhost_type(args[0]) == &LockType) + if(argc > 0 && naGhost_type(args[0]) == &LockType) { + naModUnlock(); naLock(naGhost_ptr(args[0])); + naModLock(); + } return naNil(); } @@ -74,8 +83,11 @@ static naRef f_newsem(naContext c, naRef me, int argc, naRef* args) static naRef f_semdown(naContext c, naRef me, int argc, naRef* args) { - if(argc > 0 && naGhost_type(args[0]) == &SemType) + if(argc > 0 && naGhost_type(args[0]) == &SemType) { + naModUnlock(); naSemDown(naGhost_ptr(args[0])); + naModLock(); + } return naNil(); }