discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Threading with pthreading


From: Alessio
Subject: Threading with pthreading
Date: 11 Dec 2003 09:50:58 -0800

Hi all,
  I am really stuck while mixing C/pthreads and Objective C/NSThread
calls, not even while generating a new thread and hooking it with the
runtime (oh, I'm using gcc 3.3.2 and GNUStep 1.9.0, on a Linux box).
   The problem comes when I have to create the autorelease pool for
the native
   created pool.
   First, I created a small wrapper to objc_msg_sendv:
  
void *objc_sendMsg(id __obj, SEL __sel, ...) {
      return objc_msg_sendv(__obj, __sel, __builtin_apply_args());
}

   Now, in the main function of the thread spawned by my
pthread_create() i do:
 
   GSCurrentThread();
   
   Then I should allocate and initialize an autorelease pool. 
   I thought a bit and I approached two ways:
1) emulate a [[NSAutoreleasePool alloc] init]:
    SEL alloc = sel_register_name("alloc");
    SEL init = sel_register_name("init");
    Class arp = objc_get_class("NSAutoreleasePool");
  
    id arpobj = objc_sendMsg(arp, alloc);
    objc_sendMsg(arpobj, init);
    
    Segmentation fault during init. To be detalied: in the line where
the
    else begins in the init method -> _released = _released_head.
    I then supposed that allocation hadn't been proper and alloc was
    only an emulated method so ...

2) allocate a NSAutoreleasePool instance and init it
   
     SEL init = sel_register_name("init");
     Class arp = objc_get_class("NSAutoreleasePool");
 
     id arpobj = class_create_instance(arp);
     objc_sendMsg(arpobj, init);

     This was better: I got a "Virtual memory exhausted" and my
machine
     hang up :)

Any suggestions?
Thanks in advance,
    Alessio


reply via email to

[Prev in Thread] Current Thread [Next in Thread]