discuss-gnustep
[Top][All Lists]
Advanced

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

RE: Threading with pthreading


From: Mondragon, Ian
Subject: RE: Threading with pthreading
Date: Thu, 11 Dec 2003 12:24:54 -0600

why are you using a wrapper for objc_msg_sendv and call objc methods in
straight C?  unless there's a dire need for such "cleverness", i'd say just
program in objective-c when using objective-c libraries.

- ian

-----Original Message-----
From: nail@itapac.net [mailto:nail@itapac.net]
Sent: Thursday, December 11, 2003 11:51 AM
To: discuss-gnustep@gnu.org
Subject: Threading with pthreading


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
_______________________________________________
Discuss-gnustep mailing list
Discuss-gnustep@gnu.org
http://mail.gnu.org/mailman/listinfo/discuss-gnustep




reply via email to

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