mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
Thread safety fix ... ensure notifications are sent before we become
multithrteaded. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@17757 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
d0315f7662
commit
c372a88a27
2 changed files with 41 additions and 12 deletions
|
@ -39,6 +39,7 @@
|
|||
#include <time.h>
|
||||
#endif
|
||||
|
||||
#include "Foundation/NSException.h"
|
||||
#include "Foundation/NSThread.h"
|
||||
#include "Foundation/NSLock.h"
|
||||
#include "Foundation/NSString.h"
|
||||
|
@ -366,23 +367,41 @@ static void
|
|||
gnustep_base_thread_callback()
|
||||
{
|
||||
/*
|
||||
* Post a notification if this is the first new thread to be created.
|
||||
* Won't work properly if threads are not all created by this class,
|
||||
* but it's better than nothing.
|
||||
* Protect this function with locking ... to avoid any possibility
|
||||
* of multiple threads registering with the system simultaneously,
|
||||
* and so that all NSWillBecomeMultiThreadedNotifications are sent
|
||||
* out before any second thread can interfere with anything.
|
||||
*/
|
||||
if (entered_multi_threaded_state == NO)
|
||||
{
|
||||
entered_multi_threaded_state = YES;
|
||||
|
||||
[GSPerformHolder class]; // Force initialization
|
||||
|
||||
if (nc == nil)
|
||||
[gnustep_global_lock lock];
|
||||
if (entered_multi_threaded_state == NO)
|
||||
{
|
||||
nc = [NSNotificationCenter defaultCenter];
|
||||
NS_DURING
|
||||
{
|
||||
[GSPerformHolder class]; // Force initialization
|
||||
|
||||
/*
|
||||
* Post a notification if this is the first new thread
|
||||
* to be created.
|
||||
* Won't work properly if threads are not all created
|
||||
* by this class, but it's better than nothing.
|
||||
*/
|
||||
if (nc == nil)
|
||||
{
|
||||
nc = [NSNotificationCenter defaultCenter];
|
||||
}
|
||||
[nc postNotificationName: NSWillBecomeMultiThreadedNotification
|
||||
object: nil
|
||||
userInfo: nil];
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
}
|
||||
NS_ENDHANDLER
|
||||
entered_multi_threaded_state = YES;
|
||||
}
|
||||
[nc postNotificationName: NSWillBecomeMultiThreadedNotification
|
||||
object: nil
|
||||
userInfo: nil];
|
||||
[gnustep_global_lock unlock];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue