FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Segfault
Goto page 1, 2  Next
 
Post new topic   Reply to topic     Forum Index -> Ares
View previous topic :: View next topic  
Author Message
lightoze



Joined: 12 Feb 2006
Posts: 35

PostPosted: Sat Mar 25, 2006 5:34 pm    Post subject: Segfault Reply with quote

I get segmentation fault when execute this code:
Code:
import std.c.stdio;

int main(char[][] args) {
    printf("Test.\n");
    return 0;
}

Error occurs at program termitation ("Test." is printed), at 0x0804f59a in _D3std6thread6Thread6removeFC3std6thread6ThreadZv.
Using Ares-0.17 and dmd-0.150.
Back to top
View user's profile Send private message
sean



Joined: 24 Jun 2004
Posts: 609
Location: Bay Area, CA

PostPosted: Sat Mar 25, 2006 6:10 pm    Post subject: Reply with quote

I assume this is on Windows? I'm currently in the process of rewriting the GC/thread code as per Kris' suggestion, so I'll give this a look when I'm finished.
Back to top
View user's profile Send private message
lightoze



Joined: 12 Feb 2006
Posts: 35

PostPosted: Sun Mar 26, 2006 6:14 am    Post subject: Reply with quote

sean wrote:
I assume this is on Windows?

No, I am using Gentoo linux.
Back to top
View user's profile Send private message
sean



Joined: 24 Jun 2004
Posts: 609
Location: Bay Area, CA

PostPosted: Sun Mar 26, 2006 11:14 am    Post subject: Reply with quote

In that case, you'll need to do two things:

- add this line to thread_init within the "version(Posix)" block:
Code:
main.m_isRunning = true;


- add these lines to the top of the "version(Posix)" block in Thread.start:
Code:
m_isRunning = true;
scope(failure) m_isRunning = false;


You can then remove the "obj.m_isRunning = true" line from threadStart, but it's not necessary.
Back to top
View user's profile Send private message
lightoze



Joined: 12 Feb 2006
Posts: 35

PostPosted: Mon Mar 27, 2006 2:41 am    Post subject: Reply with quote

This have not fixed the problem, now there is segfault at 0x0804f1ab in _D3std6thread6Thread6resumeFZv. Sad
Back to top
View user's profile Send private message
sean



Joined: 24 Jun 2004
Posts: 609
Location: Bay Area, CA

PostPosted: Mon Mar 27, 2006 10:43 am    Post subject: Reply with quote

Ack. I'll try to get a good build and test it out then. I still haven't actually run the Linux version of Ares.
Back to top
View user's profile Send private message
lightoze



Joined: 12 Feb 2006
Posts: 35

PostPosted: Mon Mar 27, 2006 11:22 am    Post subject: Reply with quote

Why don't you use VMWare or etc?
There are many other errors in linux threads code, for example, Thread.sleep() does not work, as well as your example of ThreadGroup usage. Crying or Very sad
P.S. what about my e-mail?
Back to top
View user's profile Send private message
sean



Joined: 24 Jun 2004
Posts: 609
Location: Bay Area, CA

PostPosted: Mon Mar 27, 2006 12:56 pm    Post subject: Reply with quote

I have an ubuntu build running on VMWare... at this point, I really just need to write a shell script to append a unittest block to all .d files, and I've had other things keeping me busy. Well, that and I haven't figured out how to write such a script. This is as far as I got:
Code:
find . -name "*.d" | xargs ...

I made a few attempts with 'cat' and redirectors but to no avail. I may just write a one-off app for the purpose.
Back to top
View user's profile Send private message
lightoze



Joined: 12 Feb 2006
Posts: 35

PostPosted: Tue Mar 28, 2006 3:37 am    Post subject: Reply with quote

append.sh:
Code:
#!/bin/sh
echo -e "\nunittest {}" >> $1

run.sh:
Code:
#!/bin/sh
find . -name "*.d" -exec ./append.sh {} \;

Both files must have executing rights for normal work.
Back to top
View user's profile Send private message
sean



Joined: 24 Jun 2004
Posts: 609
Location: Bay Area, CA

PostPosted: Thu Mar 30, 2006 2:21 pm    Post subject: Reply with quote

Thanks.

I just checked in the rewrite of std.thread, so give it a try. I've only checked that it compiles on Linux so far, but it may correct the segfault as well.
Back to top
View user's profile Send private message
lightoze



Joined: 12 Feb 2006
Posts: 35

PostPosted: Fri Mar 31, 2006 6:21 am    Post subject: Reply with quote

Yes, this have fixed bug, however there are still problems.
1) In Thread.sleep, replace Posix version with this:
Code:
if( uint.max / 1000 < milliseconds )
   {
      std.c.posix.unistd.sleep( milliseconds / 1000 );
      milliseconds ?= 1000;
   }
   if( milliseconds > 0 )
      usleep( milliseconds * 1000 );

There was two bugs, you can realise them comparing with the old version.
2) Now there are segfault when running this code:
Code:
import std.thread;
import std.c.stdio;
void fn() {
   printf( "Thread started.\n" );
   sleep( 1 );
   printf( "Thread ended.\n" );   
}
int main( char[][] args ) {
   printf( "start\n" );
   ThreadGroup d = new ThreadGroup();
   d.create( &fn );
   d.joinAll();
   printf( "run\n" );
   return 0;
}

3) This program works well, but small memory leak occurs:
Code:
import std.thread;
import std.c.stdio;
void fn() {
   printf( "Thread started.\n" );
   sleep( 1 );
   printf( "Thread ended.\n" );   
}
int main( char[][] args ) {
   while ( true ) {
      Thread t = new Thread( &fn );
      t.start();
      t.join();
      sleep( 1 );
   }
   return 0;
}
Back to top
View user's profile Send private message
sean



Joined: 24 Jun 2004
Posts: 609
Location: Bay Area, CA

PostPosted: Fri Mar 31, 2006 1:54 pm    Post subject: Reply with quote

lightoze wrote:
Yes, this have fixed bug, however there are still problems.
1) In Thread.sleep, replace Posix version with this:
Code:
if( uint.max / 1000 < milliseconds )
   {
      std.c.posix.unistd.sleep( milliseconds / 1000 );
      milliseconds ?= 1000;
   }
   if( milliseconds > 0 )
      usleep( milliseconds * 1000 );

There was two bugs, you can realise them comparing with the old version.

Yup. Thanks.
Quote:
2) Now there are segfault when running this code:
Code:
import std.thread;
import std.c.stdio;
void fn() {
   printf( "Thread started.\n" );
   sleep( 1 );
   printf( "Thread ended.\n" );   
}
int main( char[][] args ) {
   printf( "start\n" );
   ThreadGroup d = new ThreadGroup();
   d.create( &fn );
   d.joinAll();
   printf( "run\n" );
   return 0;
}

3) This program works well, but small memory leak occurs:
Code:
import std.thread;
import std.c.stdio;
void fn() {
   printf( "Thread started.\n" );
   sleep( 1 );
   printf( "Thread ended.\n" );   
}
int main( char[][] args ) {
   while ( true ) {
      Thread t = new Thread( &fn );
      t.start();
      t.join();
      sleep( 1 );
   }
   return 0;
}

With the "append unittest" script you provided I've been able to build and link against Ares, but my test program just returns immediately with no warnings or anything. I tried compiling it with and without "-version=Posix" defined, with the same result. I'm still not entirely certain whether this is a problem with how libphobos.a was constructed or if there's something else going on. I don't suppose this is something you've encountered?
Back to top
View user's profile Send private message
lightoze



Joined: 12 Feb 2006
Posts: 35

PostPosted: Fri Mar 31, 2006 3:19 pm    Post subject: Reply with quote

YARRR!!! Evil or Very Mad
All my bugs in (2) with ThreadGroup was because newly created thread is not returned in ThreadGroup.create(), please add this magnificent lines in both functions.
I don't know why you have blank output, now both programs run well. May be there are some problems with output buffering?

I am going to run several threads in backround, so I need automatically call join and delete for all finished threads. Are you planning some features of Thread class for handling it? This simple functionality is needed for many purposes and should be in Ares.

P.S. memory in (3) leak was because I forgot to delete thread instance.
Back to top
View user's profile Send private message
sean



Joined: 24 Jun 2004
Posts: 609
Location: Bay Area, CA

PostPosted: Fri Mar 31, 2006 5:22 pm    Post subject: Reply with quote

lightoze wrote:
YARRR!!! Evil or Very Mad
All my bugs in (2) with ThreadGroup was because newly created thread is not returned in ThreadGroup.create(), please add this magnificent lines in both functions.

Well that's odd. I'd declared the function to return a Thread but forgot the return statement. I'm surprised calling create wasn't causing a segfault. It's fixed now.
Quote:
I don't know why you have blank output, now both programs run well. May be there are some problems with output buffering?

I think it's something else, as even a simple "hello world" application doesn't print anything. All I did to get Ares to link successfully on Linux was to run the script you provided to add empty unittest blocks, then "make -flinux.mak" in ares/trunk/src and copy libphobos.a to /usr/lib. When compiling my test app I simply did "dmd -version=Posix test.d," so nothing too weird. I'm going to commit a few changes, resynch my Linux version and try again from scratch.
Quote:
I am going to run several threads in backround, so I need automatically call join and delete for all finished threads. Are you planning some features of Thread class for handling it? This simple functionality is needed for many purposes and should be in Ares.

ThreadGroup.joinAll was intended for the first purpose, but I suppose it would be nice there were an option to remove completed threads from the list. I've added it in the latest checkin as follows:
Code:
/**
 * Iteratively joins all tracked threads.  This function
 * will block add, remove, and opApply until it completes.
 *
 * Params:
 *  preserve = Preserve thread references.
 */
void joinAll( bool preserve = true );

As you can see, the default is to preserve thread references. This is to avoid accidental destruction of thread objects when the user actually wants to inspect object state after completion.

These changes are all checked-in, so let me know if they solve your remaining problems.
Back to top
View user's profile Send private message
lightoze



Joined: 12 Feb 2006
Posts: 35

PostPosted: Fri Mar 31, 2006 5:55 pm    Post subject: Reply with quote

I meant something like this:
Code:
void joinFinished( bool preserve = true )
{
   synchronized
   {
      foreach( Thread t; m_all )
         if ( !t.isRunning )
         {
            t.join();
            if( !preserve )
               remove( t );
         }
    }
}
Would you add this function to ThreadGroup? It might be very useful.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Ares All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group