#import <pthread.h>
#import <stdlib.h>
#import <unistd.h>

@interface MyObject
{
  Class isa;
}

+ (Class)class;
+ (void)initialize;
@end

@interface A : MyObject
@end

@interface B : MyObject
@end

@implementation MyObject
+ (Class)class
{
  return self;
}

+ (void)initialize
{
}
@end

@implementation A
+ (void)initialize
{
  usleep (10000);
  [B class];
}
@end

@implementation B
+ (void)initialize
{
  usleep (10000);
  [A class];
}
@end

static void *
thread_entry (void *arg)
{
  [A class];

  return 0;
}

int
main (int argc, char **argv)
{
  pthread_t thread_a, thread_b;

  pthread_create (&thread_a, 0, thread_entry, 0);

  /* Insert "usleep (50000);" here to avoid deadlock */
  // usleep (50000);

  [B class];

  pthread_join (thread_a, 0);

  return EXIT_SUCCESS;
}
