]>
git.saurik.com Git - wxWidgets.git/blob - interface/thread.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: documentation for wxCondition class
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
13 wxCondition variables correspond to pthread conditions or to Win32 event
14 objects. They may be used in a multithreaded application to wait until the
15 given condition becomes @true which happens when the condition becomes signaled.
17 For example, if a worker thread is doing some long task and another thread has
18 to wait until it is finished, the latter thread will wait on the condition
19 object and the worker thread will signal it on exit (this example is not
20 perfect because in this particular case it would be much better to just
21 wxThread::Wait for the worker thread, but if there are several
22 worker threads it already makes much more sense).
24 Note that a call to wxCondition::Signal may happen before the
25 other thread calls wxCondition::Wait and, just as with the
26 pthread conditions, the signal is then lost and so if you want to be sure that
27 you don't miss it you must keep the mutex associated with the condition
28 initially locked and lock it again before calling
29 wxCondition::Signal. Of course, this means that this call is
30 going to block until wxCondition::Wait is called by another
43 Default and only constructor. The @e mutex must be locked by the caller
44 before calling Wait() function.
46 Use IsOk() to check if the object was successfully
49 wxCondition(wxMutex
& mutex
);
52 Destroys the wxCondition object. The destructor is not virtual so this class
53 should not be used polymorphically.
58 Broadcasts to all waiting threads, waking all of them up. Note that this method
59 may be called whether the mutex associated with this condition is locked or
67 Returns @true if the object had been initialized successfully, @false
70 #define bool IsOk() /* implementation is private */
73 Signals the object waking up at most one thread. If several threads are waiting
74 on the same condition, the exact thread which is woken up is undefined. If no
75 threads are waiting, the signal is lost and the condition would have to be
76 signalled again to wake up any thread which may start waiting on it later.
78 Note that this method may be called whether the mutex associated with this
79 condition is locked or not.
86 Waits until the condition is signalled.
88 This method atomically releases the lock on the mutex associated with this
89 condition (this is why it must be locked prior to calling Wait) and puts the
90 thread to sleep until Signal() or
91 Broadcast() is called. It then locks the mutex
94 Note that even if Signal() had been called before
95 Wait without waking up any thread, the thread would still wait for another one
96 and so it is important to ensure that the condition will be signalled after
97 Wait or the thread may sleep forever.
99 @returns Returns wxCOND_NO_ERROR on success, another value if an error
107 Waits until the condition is signalled or the timeout has elapsed.
109 This method is identical to Wait() except that it
110 returns, with the return code of @c wxCOND_TIMEOUT as soon as the given
114 Timeout in milliseconds
116 wxCondError
WaitTimeout(unsigned long milliseconds
);
121 @class wxCriticalSectionLocker
124 This is a small helper class to be used with wxCriticalSection
125 objects. A wxCriticalSectionLocker enters the critical section in the
126 constructor and leaves it in the destructor making it much more difficult to
127 forget to leave a critical section (which, in general, will lead to serious
128 and difficult to debug problems).
135 // gs_critSect is some (global) critical section guarding access to the
137 wxCriticalSectionLocker locker(gs_critSect);
154 Without wxCriticalSectionLocker, you would need to remember to manually leave
155 the critical section before each @c return.
161 wxCriticalSection, wxMutexLocker
163 class wxCriticalSectionLocker
167 Constructs a wxCriticalSectionLocker object associated with given
168 @e criticalsection and enters it.
170 wxCriticalSectionLocker(wxCriticalSection
& criticalsection
);
173 Destructor leaves the critical section.
175 ~wxCriticalSectionLocker();
180 @class wxThreadHelper
183 The wxThreadHelper class is a mix-in class that manages a single background
184 thread. By deriving from wxThreadHelper, a class can implement the thread
185 code in its own wxThreadHelper::Entry method
186 and easily share data and synchronization objects between the main thread
187 and the worker thread. Doing this prevents the awkward passing of pointers
188 that is needed when the original object in the main thread needs to
189 synchronize with its worker thread in its own wxThread derived object.
191 For example, wxFrame may need to make some calculations
192 in a background thread and then display the results of those calculations in
195 Ordinarily, a wxThread derived object would be created
196 with the calculation code implemented in
197 wxThread::Entry. To access the inputs to the
198 calculation, the frame object would often to pass a pointer to itself to the
199 thread object. Similarly, the frame object would hold a pointer to the
200 thread object. Shared data and synchronization objects could be stored in
201 either object though the object without the data would have to access the
202 data through a pointer.
204 However, with wxThreadHelper, the frame object and the thread object are
205 treated as the same object. Shared data and synchronization variables are
206 stored in the single object, eliminating a layer of indirection and the
219 This constructor simply initializes a member variable.
224 The destructor frees the resources associated with the thread.
229 Creates a new thread. The thread object is created in the suspended state, and
231 should call @ref wxThread::run GetThread()-Run to start running
232 it. You may optionally specify the stack size to be allocated to it (Ignored on
233 platforms that don't support setting it explicitly, eg. Unix).
237 wxThreadError
Create(unsigned int stackSize
= 0);
240 This is the entry point of the thread. This function is pure virtual and must
241 be implemented by any derived class. The thread execution will start here.
243 The returned value is the thread exit code which is only useful for
244 joinable threads and is the value returned by
245 @ref wxThread::wait GetThread()-Wait.
247 This function is called by wxWidgets itself and should never be called
250 virtual ExitCode
Entry();
253 This is a public function that returns the wxThread object
254 associated with the thread.
256 wxThread
* GetThread();
261 the actual wxThread object.
267 @class wxCriticalSection
270 A critical section object is used for exactly the same purpose as
271 mutexes. The only difference is that under Windows platform
272 critical sections are only visible inside one process, while mutexes may be
273 shared between processes, so using critical sections is slightly more
274 efficient. The terminology is also slightly different: mutex may be locked (or
275 acquired) and unlocked (or released) while critical section is entered and left
278 Finally, you should try to use
279 wxCriticalSectionLocker class whenever
280 possible instead of directly using wxCriticalSection for the same reasons
281 wxMutexLocker is preferrable to
282 wxMutex - please see wxMutex for an example.
288 wxThread, wxCondition, wxCriticalSectionLocker
290 class wxCriticalSection
294 Default constructor initializes critical section object.
299 Destructor frees the resources.
301 ~wxCriticalSection();
304 Enter the critical section (same as locking a mutex). There is no error return
305 for this function. After entering the critical section protecting some global
306 data the thread running in critical section may safely use/modify it.
311 Leave the critical section allowing other threads use the global data protected
312 by it. There is no error return for this function.
322 A thread is basically a path of execution through a program. Threads are
323 sometimes called @e light-weight processes, but the fundamental difference
324 between threads and processes is that memory spaces of different processes are
325 separated while all threads share the same address space.
327 While it makes it much easier to share common data between several threads, it
329 makes it much easier to shoot oneself in the foot, so careful use of
331 objects such as mutexes or @ref overview_wxcriticalsection "critical sections"
332 is recommended. In addition, don't create global thread
333 objects because they allocate memory in their constructor, which will cause
334 problems for the memory checking system.
340 wxMutex, wxCondition, wxCriticalSection
346 This constructor creates a new detached (default) or joinable C++ thread
348 does not create or start execution of the real thread -- for this you should
349 use the Create() and Run() methods.
351 The possible values for @e kind parameters are:
357 Creates a detached thread.
362 Creates a joinable thread.
364 wxThread(wxThreadKind kind
= wxTHREAD_DETACHED
);
367 The destructor frees the resources associated with the thread. Notice that you
368 should never delete a detached thread -- you may only call
369 Delete() on it or wait until it terminates (and auto
370 destructs) itself. Because the detached threads delete themselves, they can
371 only be allocated on the heap.
373 Joinable threads should be deleted explicitly. The Delete() and Kill() functions
374 will not delete the C++ thread object. It is also safe to allocate them on
380 Creates a new thread. The thread object is created in the suspended state, and
382 should call Run() to start running it. You may optionally
383 specify the stack size to be allocated to it (Ignored on platforms that don't
384 support setting it explicitly, eg. Unix system without
385 @c pthread_attr_setstacksize). If you do not specify the stack size,
386 the system's default value is used.
388 @b Warning: It is a good idea to explicitly specify a value as systems'
389 default values vary from just a couple of KB on some systems (BSD and
390 OS/2 systems) to one or several MB (Windows, Solaris, Linux). So, if you
391 have a thread that requires more than just a few KB of memory, you will
392 have mysterious problems on some platforms but not on the common ones. On the
393 other hand, just indicating a large stack size by default will give you
394 performance issues on those systems with small default stack since those
395 typically use fully committed memory for the stack. On the contrary, if
396 use a lot of threads (say several hundred), virtual adress space can get tight
397 unless you explicitly specify a smaller amount of thread stack space for each
402 wxThreadError
Create(unsigned int stackSize
= 0);
405 Calling Delete() gracefully terminates a
406 detached thread, either when the thread calls TestDestroy() or finished
409 (Note that while this could work on a joinable thread you simply should not
410 call this routine on one as afterwards you may not be able to call
411 Wait() to free the memory of that thread).
413 See @ref overview_deletionwxthread "wxThread deletion" for a broader
414 explanation of this routine.
416 wxThreadError
Delete();
419 A common problem users experience with wxThread is that in their main thread
420 they will check the thread every now and then to see if it has ended through
421 IsRunning(), only to find that their
422 application has run into problems because the thread is using the default
423 behavior and has already deleted itself. Naturally, they instead attempt to
424 use joinable threads in place of the previous behavior.
426 However, polling a wxThread for when it has ended is in general a bad idea -
427 in fact calling a routine on any running wxThread should be avoided if
428 possible. Instead, find a way to notify yourself when the thread has ended.
429 Usually you only need to notify the main thread, in which case you can post
430 an event to it via wxPostEvent or
431 wxEvtHandler::AddPendingEvent. In
432 the case of secondary threads you can call a routine of another class
433 when the thread is about to complete processing and/or set the value
434 of a variable, possibly using mutexes and/or other
435 synchronization means if necessary.
440 This is the entry point of the thread. This function is pure virtual and must
441 be implemented by any derived class. The thread execution will start here.
443 The returned value is the thread exit code which is only useful for
444 joinable threads and is the value returned by Wait().
446 This function is called by wxWidgets itself and should never be called
449 virtual ExitCode
Entry();
452 This is a protected function of the wxThread class and thus can only be called
453 from a derived class. It also can only be called in the context of this
454 thread, i.e. a thread can only exit from itself, not from another thread.
456 This function will terminate the OS thread (i.e. stop the associated path of
457 execution) and also delete the associated C++ object for detached threads.
458 OnExit() will be called just before exiting.
460 void Exit(ExitCode exitcode
= 0);
463 Returns the number of system CPUs or -1 if the value is unknown.
467 static int GetCPUCount();
470 Returns the platform specific thread ID of the current thread as a
471 long. This can be used to uniquely identify threads, even if they are
474 static unsigned long GetCurrentId();
477 Gets the thread identifier: this is a platform dependent number that uniquely
479 thread throughout the system during its existence (i.e. the thread identifiers
482 unsigned long GetId();
485 Gets the priority of the thread, between zero and 100.
487 The following priorities are defined:
490 @b WXTHREAD_MIN_PRIORITY
495 @b WXTHREAD_DEFAULT_PRIORITY
500 @b WXTHREAD_MAX_PRIORITY
508 Returns @true if the thread is alive (i.e. started and not terminating).
510 Note that this function can only safely be used with joinable threads, not
511 detached ones as the latter delete themselves and so when the real thread is
512 no longer alive, it is not possible to call this function because
513 the wxThread object no longer exists.
518 Returns @true if the thread is of the detached kind, @false if it is a
525 Returns @true if the calling thread is the main application thread.
527 static bool IsMain();
530 Returns @true if the thread is paused.
535 Returns @true if the thread is running.
537 This method may only be safely used for joinable threads, see the remark in
543 Immediately terminates the target thread. @b This function is dangerous and
545 be used with extreme care (and not used at all whenever possible)! The resources
546 allocated to the thread will not be freed and the state of the C runtime library
547 may become inconsistent. Use Delete() for detached
548 threads or Wait() for joinable threads instead.
550 For detached threads Kill() will also delete the associated C++ object.
551 However this will not happen for joinable threads and this means that you will
552 still have to delete the wxThread object yourself to avoid memory leaks.
553 In neither case OnExit() of the dying thread will be
554 called, so no thread-specific cleanup will be performed.
556 This function can only be called from another thread context, i.e. a thread
559 It is also an error to call this function for a thread which is not running or
560 paused (in the latter case, the thread will be resumed first) -- if you do it,
561 a @c wxTHREAD_NOT_RUNNING error will be returned.
563 wxThreadError
Kill();
566 Called when the thread exits. This function is called in the context of the
567 thread associated with the wxThread object, not in the context of the main
568 thread. This function will not be called if the thread was
571 This function should never be called directly.
576 Suspends the thread. Under some implementations (Win32), the thread is
577 suspended immediately, under others it will only be suspended when it calls
578 TestDestroy() for the next time (hence, if the
579 thread doesn't call it at all, it won't be suspended).
581 This function can only be called from another thread context.
583 wxThreadError
Pause();
586 Resumes a thread suspended by the call to Pause().
588 This function can only be called from another thread context.
590 wxThreadError
Resume();
593 Starts the thread execution. Should be called after
596 This function can only be called from another thread context.
598 #define wxThreadError Run() /* implementation is private */
601 Sets the thread concurrency level for this process. This is, roughly, the
602 number of threads that the system tries to schedule to run in parallel.
603 The value of 0 for @e level may be used to set the default one.
605 Returns @true on success or @false otherwise (for example, if this function is
606 not implemented for this platform -- currently everything except Solaris).
608 static bool SetConcurrency(size_t level
);
611 Sets the priority of the thread, between 0 and 100. It can only be set
612 after calling Create() but before calling
615 The following priorities are already defined:
618 @b WXTHREAD_MIN_PRIORITY
623 @b WXTHREAD_DEFAULT_PRIORITY
628 @b WXTHREAD_MAX_PRIORITY
633 void SetPriority(int priority
);
636 Pauses the thread execution for the given amount of time.
638 This function should be used instead of wxSleep by all worker
639 threads (i.e. all except the main one).
641 static void Sleep(unsigned long milliseconds
);
644 This function should be called periodically by the thread to ensure that calls
645 to Pause() and Delete() will
646 work. If it returns @true, the thread should exit as soon as possible.
648 Notice that under some platforms (POSIX), implementation of
649 Pause() also relies on this function being called, so
650 not calling it would prevent both stopping and suspending thread from working.
652 virtual bool TestDestroy();
655 Return the thread object for the calling thread. @NULL is returned if the
657 is the main (GUI) thread, but IsMain() should be used to test
658 whether the thread is really the main one because @NULL may also be returned for
660 not created with wxThread class. Generally speaking, the return value for such
664 static wxThread
* This();
667 There are two types of threads in wxWidgets: @e detached and @e joinable,
668 modeled after the the POSIX thread API. This is different from the Win32 API
669 where all threads are joinable.
671 By default wxThreads in wxWidgets use the detached behavior. Detached threads
672 delete themselves once they have completed, either by themselves when they
674 processing or through a call to Delete(), and thus
675 must be created on the heap (through the new operator, for example).
677 joinable threads do not delete themselves when they are done processing and as
679 are safe to create on the stack. Joinable threads also provide the ability
680 for one to get value it returned from Entry()
683 You shouldn't hurry to create all the threads joinable, however, because this
684 has a disadvantage as well: you @b must Wait() for a joinable thread or the
685 system resources used by it will never be freed, and you also must delete the
686 corresponding wxThread object yourself if you did not create it on the stack.
688 contrast, detached threads are of the "fire-and-forget" kind: you only have to
690 a detached thread and it will terminate and destroy itself.
695 Waits for a joinable thread to terminate and returns the value the thread
696 returned from Entry() or @c (ExitCode)-1 on
697 error. Notice that, unlike Delete() doesn't cancel the
698 thread in any way so the caller waits for as long as it takes to the thread to
701 You can only Wait() for joinable (not detached) threads.
703 This function can only be called from another thread context.
705 See @ref overview_deletionwxthread "wxThread deletion" for a broader
706 explanation of this routine.
711 Give the rest of the thread time slice to the system allowing the other threads
713 Note that using this function is @b strongly discouraged, since in
714 many cases it indicates a design weakness of your threading model (as
715 does using Sleep functions).
716 Threads should use the CPU in an efficient manner, i.e. they should
717 do their current work efficiently, then as soon as the work is done block
718 on a wakeup event (wxCondition, wxMutex, select(), poll(), ...)
719 which will get signalled e.g. by other threads or a user device once further
720 thread work is available. Using Yield or Sleep
721 indicates polling-type behaviour, since we're fuzzily giving up our timeslice
722 and wait until sometime later we'll get reactivated, at which time we
723 realize that there isn't really much to do and Yield again...
724 The most critical characteristic of Yield is that it's operating system
725 specific: there may be scheduler changes which cause your thread to not
726 wake up relatively soon again, but instead many seconds later,
727 causing huge performance issues for your application. @b with a
728 well-behaving, CPU-efficient thread the operating system is likely to properly
729 care for its reactivation the moment it needs it, whereas with
730 non-deterministic, Yield-using threads all bets are off and the system
731 scheduler is free to penalize drastically, and this effect gets worse
732 with increasing system load due to less free CPU resources available.
733 You may refer to various Linux kernel sched_yield discussions for more
740 Regardless of whether it has terminated or not, you should call
741 Wait() on a joinable thread to release its
742 memory, as outlined in @ref overview_typeswxthread "Types of wxThreads". If you
744 a joinable thread on the heap, remember to delete it manually with the delete
745 operator or similar means as only detached threads handle this type of memory
748 Since detached threads delete themselves when they are finished processing,
749 you should take care when calling a routine on one. If you are certain the
750 thread is still running and would like to end it, you may call
751 Delete() to gracefully end it (which implies
752 that the thread will be deleted after that call to Delete()). It should be
753 implied that you should never attempt to delete a detached thread with the
754 delete operator or similar means.
756 As mentioned, Wait() or
757 Delete() attempts to gracefully terminate
758 a joinable and detached thread, respectively. It does this by waiting until
759 the thread in question calls TestDestroy()
760 or ends processing (returns from wxThread::Entry).
762 Obviously, if the thread does call TestDestroy() and does not end the calling
763 thread will come to halt. This is why it is important to call TestDestroy() in
764 the Entry() routine of your threads as often as possible.
766 As a last resort you can end the thread immediately through
767 Kill(). It is strongly recommended that you
768 do not do this, however, as it does not free the resources associated with
769 the object (although the wxThread object of detached threads will still be
770 deleted) and could leave the C runtime library in an undefined state.
775 All threads other then the "main application thread" (the one
776 wxApp::OnInit or your main function runs in, for
777 example) are considered "secondary threads". These include all threads created
778 by Create() or the corresponding constructors.
780 GUI calls, such as those to a wxWindow or
781 wxBitmap are explicitly not safe at all in secondary threads
782 and could end your application prematurely. This is due to several reasons,
783 including the underlying native API and the fact that wxThread does not run a
784 GUI event loop similar to other APIs as MFC.
786 A workaround that works on some wxWidgets ports is calling wxMutexGUIEnter
787 before any GUI calls and then calling wxMutexGUILeave afterwords. However,
788 the recommended way is to simply process the GUI calls in the main thread
789 through an event that is posted by either wxPostEvent or
790 wxEvtHandler::AddPendingEvent. This does
791 not imply that calls to these classes are thread-safe, however, as most
792 wxWidgets classes are not thread-safe, including wxString.
801 wxSemaphore is a counter limiting the number of threads concurrently accessing
802 a shared resource. This counter is always between 0 and the maximum value
803 specified during the semaphore creation. When the counter is strictly greater
804 than 0, a call to wxSemaphore::Wait returns immediately and
805 decrements the counter. As soon as it reaches 0, any subsequent calls to
806 wxSemaphore::Wait block and only return when the semaphore
807 counter becomes strictly positive again as the result of calling
808 wxSemaphore::Post which increments the counter.
810 In general, semaphores are useful to restrict access to a shared resource
811 which can only be accessed by some fixed number of clients at the same time. For
812 example, when modeling a hotel reservation system a semaphore with the counter
813 equal to the total number of available rooms could be created. Each time a room
814 is reserved, the semaphore should be acquired by calling
815 wxSemaphore::Wait and each time a room is freed it should be
816 released by calling wxSemaphore::Post.
825 Specifying a @e maxcount of 0 actually makes wxSemaphore behave as if
826 there is no upper limit. If maxcount is 1, the semaphore behaves almost as a
827 mutex (but unlike a mutex it can be released by a thread different from the one
830 @e initialcount is the initial value of the semaphore which must be between
831 0 and @e maxcount (if it is not set to 0).
833 wxSemaphore(int initialcount
= 0, int maxcount
= 0);
836 Destructor is not virtual, don't use this class polymorphically.
841 Increments the semaphore count and signals one of the waiting
842 threads in an atomic way. Returns wxSEMA_OVERFLOW if the count
843 would increase the counter past the maximum.
850 Same as Wait(), but returns immediately.
854 wxSemaError
TryWait();
857 Wait indefinitely until the semaphore count becomes strictly positive
858 and then decrement it and return.
870 This is a small helper class to be used with wxMutex
871 objects. A wxMutexLocker acquires a mutex lock in the constructor and releases
872 (or unlocks) the mutex in the destructor making it much more difficult to
873 forget to release a mutex (which, in general, will promptly lead to serious
874 problems). See wxMutex for an example of wxMutexLocker
881 wxMutex, wxCriticalSectionLocker
887 Constructs a wxMutexLocker object associated with mutex and locks it.
888 Call @ref isok() IsLocked to check if the mutex was
891 wxMutexLocker(wxMutex
& mutex
);
894 Destructor releases the mutex if it was successfully acquired in the ctor.
899 Returns @true if mutex was acquired in the constructor, @false otherwise.
901 #define bool IsOk() /* implementation is private */
909 A mutex object is a synchronization object whose state is set to signaled when
910 it is not owned by any thread, and nonsignaled when it is owned. Its name comes
911 from its usefulness in coordinating mutually-exclusive access to a shared
912 resource as only one thread at a time can own a mutex object.
914 Mutexes may be recursive in the sense that a thread can lock a mutex which it
915 had already locked before (instead of dead locking the entire process in this
916 situation by starting to wait on a mutex which will never be released while the
917 thread is waiting) but using them is not recommended under Unix and they are
918 @b not recursive there by default. The reason for this is that recursive
919 mutexes are not supported by all Unix flavours and, worse, they cannot be used
920 with wxCondition. On the other hand, Win32 mutexes are
923 For example, when several threads use the data stored in the linked list,
924 modifications to the list should only be allowed to one thread at a time
925 because during a new node addition the list integrity is temporarily broken
926 (this is also called @e program invariant).
932 wxThread, wxCondition, wxMutexLocker, wxCriticalSection
940 wxMutex(wxMutexType type
= wxMUTEX_DEFAULT
);
943 Destroys the wxMutex object.
948 Locks the mutex object. This is equivalent to
949 LockTimeout() with infinite timeout.
956 Try to lock the mutex object during the specified time interval.
960 wxMutexError
LockTimeout(unsigned long msec
);
963 Tries to lock the mutex object. If it can't, returns immediately with an error.
967 wxMutexError
TryLock();
970 Unlocks the mutex object.
974 wxMutexError
Unlock();
978 // ============================================================================
979 // Global functions/macros
980 // ============================================================================
983 Returns @true if this thread is the main one. Always returns @true if
984 @c wxUSE_THREADS is 0.
986 bool wxIsMainThread();
989 This macro combines wxCRIT_SECT_DECLARE and
990 wxCRIT_SECT_LOCKER: it creates a static critical
991 section object and also the lock object associated with it. Because of this, it
992 can be only used inside a function, not at global scope. For example:
996 static int s_counter = 0;
998 wxCRITICAL_SECTION(counter);
1004 (note that we suppose that the function is called the first time from the main
1005 thread so that the critical section object is initialized correctly by the time
1006 other threads start calling it, if this is not the case this approach can
1007 @b not be used and the critical section must be made a global instead).
1009 #define wxCRITICAL_SECTION(name) /* implementation is private */
1012 This macro declares a critical section object named @e cs if
1013 @c wxUSE_THREADS is 1 and does nothing if it is 0. As it doesn't
1014 include the @c static keyword (unlike
1015 wxCRIT_SECT_DECLARE), it can be used to declare
1016 a class or struct member which explains its name.
1018 #define wxCRIT_SECT_DECLARE(cs) /* implementation is private */
1021 This function must be called when any thread other than the main GUI thread
1022 wants to get access to the GUI library. This function will block the execution
1023 of the calling thread until the main thread (or any other thread holding the
1024 main GUI lock) leaves the GUI library and no other thread will enter the GUI
1025 library until the calling thread calls ::wxMutexGuiLeave.
1027 Typically, these functions are used like this:
1029 void MyThread::Foo(void)
1031 // before doing any GUI calls we must ensure that this thread is the only
1037 my_window-DrawSomething();
1043 Note that under GTK, no creation of top-level windows is allowed in any
1044 thread but the main one.
1046 This function is only defined on platforms which support preemptive
1049 void wxMutexGuiEnter();
1052 This macro declares a (static) critical section object named @e cs if
1053 @c wxUSE_THREADS is 1 and does nothing if it is 0.
1055 #define wxCRIT_SECT_DECLARE(cs) /* implementation is private */
1058 This macro is equivalent to @ref wxCriticalSection::leave cs.Leave if
1059 @c wxUSE_THREADS is 1 and does nothing if it is 0.
1061 #define wxLEAVE_CRIT_SECT(wxCriticalSection& cs) /* implementation is private */
1064 This macro creates a @ref overview_wxcriticalsectionlocker "critical section
1066 object named @e name and associated with the critical section @e cs if
1067 @c wxUSE_THREADS is 1 and does nothing if it is 0.
1069 #define wxCRIT_SECT_LOCKER(name, cs) /* implementation is private */
1072 This macro is equivalent to @ref wxCriticalSection::enter cs.Enter if
1073 @c wxUSE_THREADS is 1 and does nothing if it is 0.
1075 #define wxENTER_CRIT_SECT(wxCriticalSection& cs) /* implementation is private */