Right, with Ns_ functions it does not crash.

Stephen Deasey wrote:
On 12/19/06, Zoran Vasiljevic <[EMAIL PROTECTED]> wrote:
On 19.12.2006, at 17:08, Vlad Seryakov wrote:

I converted all to use pthreads directly instead of Tcl wrappers, and
now it does not crash anymore. Will continue testing but it looks like
Tcl is the problem here, not ptmalloc
Where does it crash? I see you are just using
Tcl_CreateThread
Tcl_MutexLock/Unlock
Tcl_JoinThread
Those just fallback to underlying pthread lib.
It makes no real sense. I believe.


Simply loading the Tcl library initialises a bunch of thread stuff,
right?  Also, the Tcl mutexes are self initialising, which includes
calling down into the global Tcl mutex.  Lots of stuff going on behind
the scenes...

NaviServer mutexes are also self initialising, but they call down to
the pthread_ functions without touching any Tcl code, which may
explain why the server isn't crashing all the time.

So here's a test: what happens when you compile the test program to
use Ns_Mutex and Ns_ThreadCreate etc.? Pthreads work, Tcl doesn't, how
about NaviServer?

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
naviserver-devel mailing list
naviserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/naviserver-devel


--
Vlad Seryakov
571 262-8608 office
[EMAIL PROTECTED]
http://www.crystalballinc.com/vlad/

/*
 * gcc -I/usr/local/ns/include -g ttest.c -o ttest -lpthread /usr/local/ns/lib/libnsthread.so
 *
 */

#include <ns.h>
#include <stdlib.h>
#include <memory.h>
#include <unistd.h>
#include <signal.h>
#include <pthread.h>

#define MemAlloc malloc
#define MemFree free

static int nbuffer = 16384;
static int nloops = 150000;
static int nthreads = 12;

static void *gPtr = NULL;
static Ns_Mutex gLock;

void MemThread(void *arg)
{
     int   i,n;
     void *ptr = NULL;

     for (i = 0; i < nloops; ++i) {
         n = 1 + (int) (nbuffer * (rand() / (RAND_MAX + 1.0)));
         if (ptr != NULL) {
             MemFree(ptr);
         }
         ptr = MemAlloc(n);
         if (n % 50 == 0) {
             Ns_MutexLock(&gLock);
             if (gPtr != NULL) {
                 MemFree(gPtr);
                 gPtr = NULL;
             } else {
                 gPtr = MemAlloc(n);
             }
             Ns_MutexUnlock(&gLock);
         }
     }
}

int main (int argc, char **argv)
{
    int i;
    Ns_Thread *tids;

    if (argc > 1) {
        nthreads = atoi(argv[1]);
    }
    if (argc > 2) {
        nloops = atoi(argv[2]);
    }
    if (argc > 3) {
        nbuffer = atoi(argv[3]);
    }

    tids = (Ns_Thread *)malloc(sizeof(Tcl_ThreadId) * nthreads);

    for (i = 0; i < nthreads; ++i) {
        Ns_ThreadCreate(MemThread, 0, 0, &tids[i]);
    }
    for (i = 0; i < nthreads; ++i) {
        Ns_ThreadJoin(&tids[i], NULL);
    }
}



Reply via email to