mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
TG: Fix config.initialize.m
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32472 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
98c91159d9
commit
7fd6ab7ca8
2 changed files with 48 additions and 30 deletions
|
@ -1,3 +1,9 @@
|
|||
2011-03-06 Thomas Gamper <icicle@cg.tuwien.ac.at>
|
||||
|
||||
* config/config.initialize.m: add missing include to fix build.
|
||||
Reformat, use correct thread handles, adapt sleep times to
|
||||
worst case. Remove C99-ism.
|
||||
|
||||
2011-03-06 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSThread.m: remove obsolete call to objc_set_thread_callback().
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "objc-common.g"
|
||||
#include <pthread.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define mySleep(X) usleep(1000*(X))
|
||||
|
@ -18,7 +18,9 @@ static BOOL may_proceed = NO;
|
|||
|
||||
@interface MyClass : NSObject
|
||||
@end
|
||||
|
||||
@implementation MyClass
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
initialize_entered++;
|
||||
|
@ -26,11 +28,13 @@ static BOOL may_proceed = NO;
|
|||
mySleep(1);
|
||||
initialize_exited++;
|
||||
}
|
||||
|
||||
+ (Class) class
|
||||
{
|
||||
class_entered++;
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
static void test(void *arg)
|
||||
|
@ -41,44 +45,52 @@ static void test(void *arg)
|
|||
int
|
||||
main()
|
||||
{
|
||||
pthread_t t1;
|
||||
pthread_t t2;
|
||||
pthread_t t1;
|
||||
pthread_t t2;
|
||||
unsigned counter = 0;
|
||||
|
||||
if (0 == pthread_create(&t1, 0, test, 0))
|
||||
{
|
||||
unsigned counter = 0;
|
||||
|
||||
while (0 == initialize_entered && counter++ < 3)
|
||||
{
|
||||
mySleep(1);
|
||||
}
|
||||
if (0 == initialize_entered)
|
||||
{
|
||||
fprintf(stderr, "Failed to initialize\n");
|
||||
return 1;
|
||||
}
|
||||
if (0 == pthread_create(&t1, 0, test, 0))
|
||||
{
|
||||
mySleep(1);
|
||||
if (class_entered > 0)
|
||||
{
|
||||
fprintf(stderr, "class entered prematurely\n");
|
||||
mySleep(1);
|
||||
}
|
||||
|
||||
if (0 == initialize_entered)
|
||||
{
|
||||
fprintf(stderr, "Failed to initialize\n");
|
||||
return 1;
|
||||
}
|
||||
may_proceed = YES;
|
||||
mySleep(1);
|
||||
if (2 == class_entered)
|
||||
{
|
||||
return 0; // OK
|
||||
|
||||
if (0 == pthread_create(&t2, 0, test, 0))
|
||||
{
|
||||
mySleep(1);
|
||||
|
||||
if (class_entered > 0)
|
||||
{
|
||||
fprintf(stderr, "class entered prematurely\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
may_proceed = YES;
|
||||
|
||||
// sleep longer than t1 may need to complete initialize
|
||||
// plus time for t1 and t2 to complete "test"
|
||||
mySleep(2);
|
||||
|
||||
if (2 == class_entered)
|
||||
{
|
||||
return 0; // OK
|
||||
}
|
||||
|
||||
fprintf(stderr, "problem with initialize\n");
|
||||
return 1;
|
||||
}
|
||||
fprintf(stderr, "problem with initialize\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "failed to create t2\n");
|
||||
return 1;
|
||||
}
|
||||
{
|
||||
fprintf(stderr, "failed to create t2\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue