Commit Graph

27 Commits

Author SHA1 Message Date
pierre
42be0dd306 Use ptruint instead of longint cast for self address for WRITE_DEBUG
git-svn-id: trunk@29054 -
2014-11-10 23:09:06 +00:00
Jonas Maebe
77c1364713 * replaced use of semaphores in Unix version of TThread for suspend/resume
functionality with RTLEvent:
   o the thread manager semaphore functionality isn't used for anything else,
     and the main difference between mutex/condvar and semaphores is that the
     latter can be used for IPC (while the thread manager is always used
     within a single process) and that they are counting (but since a thread
     can only suspend itself nowadays, it cannot be suspended recursively)
   o OS X sandboxing does not support the use of semaphores (or rather: Apple
     does not allow sandboxing rules that enable the use of IPC semaphores in
     the appstore)

git-svn-id: trunk@28965 -
2014-11-02 15:00:24 +00:00
Jonas Maebe
79a40547ca - removed no longer used tthread.FSuspendedExternal
git-svn-id: trunk@28963 -
2014-11-02 15:00:14 +00:00
sergei
d7c863185f * Added plain calls for semaphore-related functionality, this removes need to maintain a second copy of thread manager in unis/tthread.inc.
git-svn-id: trunk@27665 -
2014-04-26 13:58:35 +00:00
sergei
471ffb017c - Removed call to FlushThread, it is redundant since r17798. SysFlushStdio is called from DoneThreads, which is in turn called after exiting from ThreadFunc.
git-svn-id: trunk@27663 -
2014-04-26 13:46:10 +00:00
Jonas Maebe
cada770f9e * changed return value in case of failure in ThreadManager.SemaphoreInit
from nil to pointer(-1), because nil/0 is a valid return value for
    sem_open() on some platforms

git-svn-id: trunk@26079 -
2013-11-13 16:51:11 +00:00
svenbarth
fbceb574eb Fix for Mantis #25041 . Correctly set CurrentThreadVar for those tthread.inc incarnations that don't use the default ThreadProc in classes.inc (this should be changed in the future though...). In addition to Unix systems as described by the bug report this also involved BeOS and Netware LibC.
+ added test

git-svn-id: trunk@25511 -
2013-09-17 18:02:12 +00:00
svenbarth
764f36a179 Extend TThread with (class) methods and (class) properties from Delphi 2007 and newer.
Especially for the introduction of the Queue method the internal Synchronize handling was modified. Instead of handling only one event there is now a queue of events which is walked completely when CheckSynchronize is called. Each entry in the queue can carry a PRTLEvent which will be signaled when the contained method has been executed and thus Synchronize methods can still be blocking.
Exceptions inside the queued methods are either handed back to the calling method for Synchronize events or raised directly (after leaving the queue in a valid state) to the caller of CheckSynchronize.

The way platform specific adjustments can be made to TThread was changed. Instead of implementing the Constructor and Destructor directly one now implements the methods SysCreate and SysDestroy which are called from the Constructor and Destructor respectively. All RTLs were adjusted for this and should be controlled by the platform maintainers for correct compilation (Unix works).

The new method NameThreadForDebugging has two overloaded variants: one with the thread name as AnsiString and one with the thread name as UnicodeString.
By default the AnsiString variant calls the UnicodeString variant and the latter needs to be implemented. This can be changed by defining THREADNAME_IS_ANSISTRING for a platform. Then the UnicodeString variant calls the AnsiString one and the AnsiString one needs to be implemented.

Also added was a global property CPUCount for the System unit. This property returns the number of virtual cores of the system.

New methods and functions that should be implemented per platform are:
System.GetCPUCount (default returns 1)
Classes.TThread.GetSystemTimes (default zeros the struct)
Classes.TThread.NameThreadForDebugging (default does nothing)

More detailed information about the added methods will be available in the feature announcement mail.

git-svn-id: trunk@23227 -
2012-12-27 16:16:17 +00:00
michael
8dd254b281 * Fixed synchronize/waitfor issue
git-svn-id: trunk@16145 -
2010-10-12 18:08:24 +00:00
Jonas Maebe
d7cdd9afba * allow tthread-based threads to only start executing once the constructor
has finished running (based on patch by Jared Davison, mantis #16884)

git-svn-id: trunk@15599 -
2010-07-18 16:31:25 +00:00
Jonas Maebe
b214448b9e * don't access the thread instance after calling DoTerminate to avoid
race conditions in case DoTerminate can cause the thread to be freed
    already. Side-effect: changing FreeOnTerminate in DoTerminate no longer
    has any effects, but this is compatible with the generic code for
    ThreadProc in objpas/classes/classes.inc (patch by Nikolai ZHUBR)

git-svn-id: trunk@14504 -
2009-12-30 14:46:56 +00:00
Jonas Maebe
8349cde7db * changed byte/word/longbool to be Delphi-compatible (+ similar changes
for qwordbool) + test:
    o assigning true to such a variable now sets them to $ff/$ffff/$ffffffff
    o these types are now all signed
    o converting an integer type to a byte/word/long/qwordbool using an
      explicit type cast keeps the integer's original value stored in the
      bool, instead of forcing it to ord(true)/ord(false)
    (mantis #10233 and #10613, implemented for all architectures, testsuite
     tested for ppc32, sparc and x86)
  * fixed some places where the rtl depended on longbool(true) having the
    value 1
  * extended several boolean tests (and adapted some to no longer assume
    that byte/word/long/qwordbool(true)=1)
  + support for converting to qwordbool in second_int_to_bool for x86, ppc
    and sparc

git-svn-id: trunk@9898 -
2008-01-24 21:30:55 +00:00
Jonas Maebe
4e78a30ee3 * only print exception backtrace at end of unhandled exception in
tthread in case rtl is compiled with -dDEBUG_MT

git-svn-id: trunk@8595 -
2007-09-21 15:09:08 +00:00
Jonas Maebe
f3a00b0731 * cache result of GetThreadManager in InitThreads
git-svn-id: trunk@8245 -
2007-08-08 11:33:54 +00:00
micha
dd350255a4 * print thread handle unsigned in unix thread debug info
git-svn-id: trunk@8094 -
2007-07-18 20:14:48 +00:00
micha
721ae51cd0 * dump stack when thread terminates because of exception (unix)
git-svn-id: trunk@8093 -
2007-07-18 20:13:39 +00:00
Jonas Maebe
172f85c8c3 * fixed important typo in better comments :)
git-svn-id: trunk@7618 -
2007-06-09 20:37:26 +00:00
Jonas Maebe
e93d612f4a * fixed FFreeOnTerminate handing in destructor + better comments
git-svn-id: trunk@7617 -
2007-06-09 20:36:35 +00:00
Jonas Maebe
4dd3be0e5a * return thread function result via pthread_exit() from CBeginThread
(Vinzent Hoefler)
  * simplified CWaitForThreadTerminate based on comments from Vinzent
    Hoefler
  * fixed resource leaks where in some cases a pthread would not be
    reaped based on comments from Vinzent Hoefler (resolves #9016)

git-svn-id: trunk@7588 -
2007-06-06 15:18:48 +00:00
Jonas Maebe
526a79a3c6 * disable thread suspension from another thread under *nix, see added
comments in cthreads.pp why

git-svn-id: trunk@7551 -
2007-06-02 11:39:59 +00:00
Jonas Maebe
157e5eb02e * fixed debug code for 64 bit
git-svn-id: trunk@5913 -
2007-01-12 09:12:13 +00:00
Jonas Maebe
652d331922 * fixed 64 bit compilation
git-svn-id: trunk@5680 -
2006-12-22 16:50:09 +00:00
Jonas Maebe
cf4b3f2e4d * don't destroy fsem in tthread.destroy before its potential last use
git-svn-id: trunk@5678 -
2006-12-22 14:53:54 +00:00
Jonas Maebe
4cbbfd7f5c * set FSuspended also if a tthread is suspended by an external thread
on unix
  * fixed some dataraces in unix' suspend/resume (although they can't
    be solved completely due to no possibility to atomically
    suspend/resume and set fsuspended at the same time)

git-svn-id: trunk@5677 -
2006-12-22 14:49:49 +00:00
Jonas Maebe
1867a46f34 - disabled fix for mantis 6693 from r5662 since the fix itself also
contains a race condition

git-svn-id: trunk@5670 -
2006-12-21 23:11:35 +00:00
Jonas Maebe
96b379ab0b * fixed initial suspending bug in r5662
git-svn-id: trunk@5668 -
2006-12-21 21:51:41 +00:00
Jonas Maebe
0c3afc0cf4 + implementation of cSemaphore* and BasicRTLEvent based on
sem_open/sem_close for Darwin (doesn't have sem_init/sem_destroy)
  + implementation of cSemaphore* based on pipes (for potential future
    systems that don't have either sem* routines)
  + test for basicrtlevent
  * fixed datarace whereby a TThread could be started, run and exit before
    TThread.AfterConstructor had been called (Mantis 6693, all platforms)
  * throw EThread exceptions in TThread.create if something during creating
    the tthread goes wrong (*nix)
  * don't crash in TThread.Destroy if the TThread throws an exception before
    it was fully initialised (*nix)
  * changed order of operations in TThread.Destroy so it doesn't perform
    invalid thread operations in some edge cases (*nix)
  * fixed usage of sem_wait/sem_trywait (can be interrupted) in Semaphore
    and RTLEvent implementations
  * fixed erroneous waiting for threads after they had already exited via
    pthread_detach/pthread_exit
  * fixed several memory leaks in case of thread intialisation errors
    (*nix)
  * unified tthread.inc for all Unices

git-svn-id: trunk@5662 -
2006-12-21 18:22:47 +00:00