Thread.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  1. //
  2. // System.Threading.Thread.cs
  3. //
  4. // Author:
  5. // Dick Porter ([email protected])
  6. //
  7. // (C) Ximian, Inc. http://www.ximian.com
  8. // Copyright (C) 2004 Novell (http://www.novell.com)
  9. //
  10. //
  11. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  12. //
  13. // Permission is hereby granted, free of charge, to any person obtaining
  14. // a copy of this software and associated documentation files (the
  15. // "Software"), to deal in the Software without restriction, including
  16. // without limitation the rights to use, copy, modify, merge, publish,
  17. // distribute, sublicense, and/or sell copies of the Software, and to
  18. // permit persons to whom the Software is furnished to do so, subject to
  19. // the following conditions:
  20. //
  21. // The above copyright notice and this permission notice shall be
  22. // included in all copies or substantial portions of the Software.
  23. //
  24. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  28. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  29. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  30. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  31. //
  32. using System.Runtime.Remoting.Contexts;
  33. using System.Security.Permissions;
  34. using System.Security.Principal;
  35. using System.Globalization;
  36. using System.Runtime.CompilerServices;
  37. using System.Collections;
  38. #if NET_2_0
  39. using System.Runtime.ConstrainedExecution;
  40. using System.Runtime.InteropServices;
  41. #endif
  42. namespace System.Threading
  43. {
  44. public sealed class Thread
  45. {
  46. #region Sync with object.h
  47. // stores a thread handle
  48. private IntPtr system_thread_handle;
  49. private CultureInfo current_culture;
  50. private CultureInfo current_ui_culture;
  51. private bool threadpool_thread;
  52. /* accessed only from unmanaged code */
  53. private IntPtr name;
  54. private int name_len;
  55. private ThreadState state = ThreadState.Unstarted;
  56. private object abort_exc;
  57. internal object abort_state;
  58. /* thread_id is only accessed from unmanaged code */
  59. private int thread_id;
  60. /* start_notify is used by the runtime to signal that Start()
  61. * is ok to return
  62. */
  63. private IntPtr start_notify;
  64. private IntPtr stack_ptr;
  65. private IntPtr static_data;
  66. private IntPtr jit_data;
  67. private IntPtr lock_data;
  68. private IntPtr appdomain_refs;
  69. private bool interruption_requested;
  70. private IntPtr suspend_event;
  71. private IntPtr resume_event;
  72. private object synch_lock = new Object();
  73. #endregion
  74. private ThreadStart threadstart;
  75. private string thread_name=null;
  76. private IPrincipal _principal;
  77. public static Context CurrentContext {
  78. get {
  79. return(AppDomain.InternalGetContext ());
  80. }
  81. }
  82. public static IPrincipal CurrentPrincipal {
  83. get {
  84. IPrincipal p = null;
  85. Thread th = CurrentThread;
  86. lock (th) {
  87. p = th._principal;
  88. if (p == null) {
  89. p = GetDomain ().DefaultPrincipal;
  90. th._principal = p;
  91. }
  92. }
  93. return p;
  94. }
  95. [SecurityPermission (SecurityAction.Demand, Flags=SecurityPermissionFlag.ControlPolicy)]
  96. set {
  97. CurrentThread._principal = value;
  98. }
  99. }
  100. // Looks up the object associated with the current thread
  101. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  102. private extern static Thread CurrentThread_internal();
  103. public static Thread CurrentThread {
  104. #if NET_2_0
  105. [ReliabilityContract (Consistency.WillNotCorruptState, CER.MayFail)]
  106. #endif
  107. get {
  108. return(CurrentThread_internal());
  109. }
  110. }
  111. internal static int CurrentThreadId {
  112. get {
  113. return CurrentThread.thread_id;
  114. }
  115. }
  116. // Looks up the slot hash for the current thread
  117. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  118. private extern static Hashtable SlotHash_lookup();
  119. // Stores the slot hash for the current thread
  120. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  121. private extern static void SlotHash_store(Hashtable slothash);
  122. private static Hashtable GetTLSSlotHash() {
  123. Hashtable slothash=SlotHash_lookup();
  124. if(slothash==null) {
  125. // Not synchronised, because this is
  126. // thread specific anyway.
  127. slothash=new Hashtable();
  128. SlotHash_store(slothash);
  129. }
  130. return(slothash);
  131. }
  132. internal static object ResetDataStoreStatus () {
  133. Hashtable slothash=SlotHash_lookup();
  134. SlotHash_store(null);
  135. return slothash;
  136. }
  137. internal static void RestoreDataStoreStatus (object data) {
  138. SlotHash_store((Hashtable)data);
  139. }
  140. public static LocalDataStoreSlot AllocateDataSlot() {
  141. LocalDataStoreSlot slot = new LocalDataStoreSlot();
  142. return(slot);
  143. }
  144. // Stores a hash keyed by strings of LocalDataStoreSlot objects
  145. static Hashtable datastorehash;
  146. private static object datastore_lock = new object ();
  147. private static void InitDataStoreHash () {
  148. lock (datastore_lock) {
  149. if (datastorehash == null) {
  150. datastorehash = Hashtable.Synchronized(new Hashtable());
  151. }
  152. }
  153. }
  154. public static LocalDataStoreSlot AllocateNamedDataSlot(string name) {
  155. lock (datastore_lock) {
  156. if (datastorehash == null)
  157. InitDataStoreHash ();
  158. LocalDataStoreSlot slot = (LocalDataStoreSlot)datastorehash[name];
  159. if(slot!=null) {
  160. // This exception isnt documented (of
  161. // course) but .net throws it
  162. throw new ArgumentException("Named data slot already added");
  163. }
  164. slot = new LocalDataStoreSlot();
  165. datastorehash.Add(name, slot);
  166. return(slot);
  167. }
  168. }
  169. public static void FreeNamedDataSlot(string name) {
  170. lock (datastore_lock) {
  171. if (datastorehash == null)
  172. InitDataStoreHash ();
  173. LocalDataStoreSlot slot=(LocalDataStoreSlot)datastorehash[name];
  174. if(slot!=null) {
  175. datastorehash.Remove(slot);
  176. }
  177. }
  178. }
  179. public static object GetData(LocalDataStoreSlot slot) {
  180. Hashtable slothash=GetTLSSlotHash();
  181. return(slothash[slot]);
  182. }
  183. public static AppDomain GetDomain() {
  184. return AppDomain.CurrentDomain;
  185. }
  186. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  187. public extern static int GetDomainID();
  188. public static LocalDataStoreSlot GetNamedDataSlot(string name) {
  189. lock (datastore_lock) {
  190. if (datastorehash == null)
  191. InitDataStoreHash ();
  192. LocalDataStoreSlot slot=(LocalDataStoreSlot)datastorehash[name];
  193. if(slot==null) {
  194. slot=AllocateNamedDataSlot(name);
  195. }
  196. return(slot);
  197. }
  198. }
  199. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  200. private extern static void ResetAbort_internal();
  201. public static void ResetAbort()
  202. {
  203. ResetAbort_internal();
  204. }
  205. public static void SetData(LocalDataStoreSlot slot,
  206. object data) {
  207. Hashtable slothash=GetTLSSlotHash();
  208. if(slothash.Contains(slot)) {
  209. slothash.Remove(slot);
  210. }
  211. slothash.Add(slot, data);
  212. }
  213. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  214. private extern static void Sleep_internal(int ms);
  215. public static void Sleep(int millisecondsTimeout) {
  216. if((millisecondsTimeout<0) && (millisecondsTimeout != Timeout.Infinite)) {
  217. throw new ArgumentException("Negative timeout");
  218. }
  219. Thread thread=CurrentThread;
  220. Sleep_internal(millisecondsTimeout);
  221. }
  222. public static void Sleep(TimeSpan timeout) {
  223. // LAMESPEC: says to throw ArgumentException too
  224. int ms=Convert.ToInt32(timeout.TotalMilliseconds);
  225. if(ms < 0 || ms > Int32.MaxValue) {
  226. throw new ArgumentOutOfRangeException("Timeout out of range");
  227. }
  228. Thread thread=CurrentThread;
  229. Sleep_internal(ms);
  230. }
  231. // Returns the system thread handle
  232. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  233. private extern IntPtr Thread_internal(ThreadStart start);
  234. public Thread(ThreadStart start) {
  235. if(start==null) {
  236. throw new ArgumentNullException("Null ThreadStart");
  237. }
  238. threadstart=start;
  239. }
  240. [MonoTODO]
  241. #if NET_2_0
  242. [Obsolete ("")]
  243. #endif
  244. public ApartmentState ApartmentState {
  245. get {
  246. return(ApartmentState.Unknown);
  247. }
  248. set {
  249. }
  250. }
  251. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  252. private static extern int current_lcid ();
  253. /* If the current_lcid() isn't known by CultureInfo,
  254. * it will throw an exception which may cause
  255. * String.Concat to try and recursively look up the
  256. * CurrentCulture, which will throw an exception, etc.
  257. * Use a boolean to short-circuit this scenario.
  258. */
  259. private static bool in_currentculture=false;
  260. public CultureInfo CurrentCulture {
  261. get {
  262. if (current_culture == null) {
  263. lock (typeof (Thread)) {
  264. if(current_culture==null) {
  265. if(in_currentculture==true) {
  266. /* Bail out */
  267. current_culture = CultureInfo.InvariantCulture;
  268. } else {
  269. in_currentculture=true;
  270. current_culture = CultureInfo.ConstructCurrentCulture ();
  271. }
  272. }
  273. in_currentculture=false;
  274. }
  275. }
  276. return(current_culture);
  277. }
  278. set {
  279. current_culture = value;
  280. }
  281. }
  282. public CultureInfo CurrentUICulture {
  283. get {
  284. if (current_ui_culture == null) {
  285. lock (synch_lock) {
  286. if(current_ui_culture==null) {
  287. /* We don't
  288. * distinguish
  289. * between
  290. * System and
  291. * UI cultures
  292. */
  293. current_ui_culture = CultureInfo.ConstructCurrentUICulture ();
  294. }
  295. }
  296. }
  297. return(current_ui_culture);
  298. }
  299. set {
  300. current_ui_culture = value;
  301. }
  302. }
  303. public bool IsThreadPoolThread {
  304. get {
  305. return IsThreadPoolThreadInternal;
  306. }
  307. }
  308. internal bool IsThreadPoolThreadInternal {
  309. get {
  310. return threadpool_thread;
  311. }
  312. set {
  313. threadpool_thread = value;
  314. }
  315. }
  316. public bool IsAlive {
  317. get {
  318. ThreadState curstate=state;
  319. if((curstate & ThreadState.Aborted) != 0 ||
  320. (curstate & ThreadState.Stopped) != 0 ||
  321. (curstate & ThreadState.Unstarted) != 0) {
  322. return(false);
  323. } else {
  324. return(true);
  325. }
  326. }
  327. }
  328. public bool IsBackground {
  329. get {
  330. if((state & ThreadState.Background) != 0) {
  331. return(true);
  332. } else {
  333. return(false);
  334. }
  335. }
  336. set {
  337. if(value==true) {
  338. set_state(ThreadState.Background);
  339. } else {
  340. clr_state(ThreadState.Background);
  341. }
  342. }
  343. }
  344. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  345. private extern string GetName_internal ();
  346. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  347. private extern void SetName_internal (String name);
  348. /*
  349. * The thread name must be shared by appdomains, so it is stored in
  350. * unmanaged code.
  351. */
  352. public string Name {
  353. get {
  354. return GetName_internal ();
  355. }
  356. set {
  357. lock (synch_lock) {
  358. if(Name!=null) {
  359. throw new InvalidOperationException ("Thread.Name can only be set once.");
  360. }
  361. SetName_internal (value);
  362. }
  363. }
  364. }
  365. [MonoTODO]
  366. public ThreadPriority Priority {
  367. get {
  368. return(ThreadPriority.Lowest);
  369. }
  370. set {
  371. }
  372. }
  373. public ThreadState ThreadState {
  374. get {
  375. return(state);
  376. }
  377. }
  378. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  379. private extern void Abort_internal (object stateInfo);
  380. public void Abort() {
  381. Abort_internal (null);
  382. }
  383. public void Abort(object stateInfo) {
  384. Abort_internal(stateInfo);
  385. }
  386. [MonoTODO]
  387. public void Interrupt() {
  388. }
  389. // The current thread joins with 'this'. Set ms to 0 to block
  390. // until this actually exits.
  391. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  392. private extern bool Join_internal(int ms, IntPtr handle);
  393. public void Join() {
  394. if((state & ThreadState.Unstarted) != 0) {
  395. throw new ThreadStateException("Thread has not been started");
  396. }
  397. Thread thread=CurrentThread;
  398. Join_internal(Timeout.Infinite, system_thread_handle);
  399. }
  400. public bool Join(int millisecondsTimeout) {
  401. if (millisecondsTimeout != Timeout.Infinite && millisecondsTimeout < 0)
  402. throw new ArgumentException ("Timeout less than zero", "millisecondsTimeout");
  403. if((state & ThreadState.Unstarted) != 0) {
  404. throw new ThreadStateException("Thread has not been started");
  405. }
  406. Thread thread=CurrentThread;
  407. return Join_internal(millisecondsTimeout, system_thread_handle);
  408. }
  409. public bool Join(TimeSpan timeout) {
  410. // LAMESPEC: says to throw ArgumentException too
  411. int ms=Convert.ToInt32(timeout.TotalMilliseconds);
  412. if(ms < 0 || ms > Int32.MaxValue) {
  413. throw new ArgumentOutOfRangeException("timeout out of range");
  414. }
  415. if((state & ThreadState.Unstarted) != 0) {
  416. throw new ThreadStateException("Thread has not been started");
  417. }
  418. Thread thread=CurrentThread;
  419. return Join_internal(ms, system_thread_handle);
  420. }
  421. #if NET_1_1
  422. [MonoTODO ("seems required for multi-processors systems like Itanium")]
  423. public static void MemoryBarrier ()
  424. {
  425. throw new NotImplementedException ();
  426. }
  427. #endif
  428. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  429. private extern void Resume_internal();
  430. #if NET_2_0
  431. [Obsolete ("")]
  432. #endif
  433. public void Resume ()
  434. {
  435. if ((state & ThreadState.Unstarted) != 0 || !IsAlive ||
  436. ((state & ThreadState.Suspended) == 0 && (state & ThreadState.SuspendRequested) == 0))
  437. {
  438. throw new ThreadStateException("Thread has not been started, or is dead");
  439. }
  440. Resume_internal ();
  441. }
  442. [MonoTODO]
  443. public static void SpinWait (int iterations)
  444. {
  445. throw new NotImplementedException ();
  446. }
  447. // Launches the thread
  448. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  449. private extern void Start_internal(IntPtr handle);
  450. public void Start() {
  451. lock(synch_lock) {
  452. if((state & ThreadState.Unstarted) == 0) {
  453. throw new ThreadStateException("Thread has already been started");
  454. }
  455. // Thread_internal creates the new thread, but
  456. // blocks it until Start() is called later.
  457. system_thread_handle=Thread_internal(threadstart);
  458. if (system_thread_handle == (IntPtr) 0) {
  459. throw new SystemException ("Thread creation failed");
  460. }
  461. // Launch this thread
  462. Start_internal(system_thread_handle);
  463. // Mark the thread state as Running
  464. // (which is all bits
  465. // cleared). Therefore just remove the
  466. // Unstarted bit
  467. clr_state(ThreadState.Unstarted);
  468. }
  469. }
  470. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  471. private extern void Suspend_internal();
  472. #if NET_2_0
  473. [Obsolete ("")]
  474. #endif
  475. public void Suspend() {
  476. if((state & ThreadState.Unstarted) != 0 || !IsAlive) {
  477. throw new ThreadStateException("Thread has not been started, or is dead");
  478. }
  479. Suspend_internal ();
  480. }
  481. // Closes the system thread handle
  482. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  483. private extern void Thread_free_internal(IntPtr handle);
  484. ~Thread() {
  485. // Free up the handle
  486. if (system_thread_handle != (IntPtr) 0)
  487. Thread_free_internal(system_thread_handle);
  488. }
  489. private void set_state(ThreadState set) {
  490. lock(synch_lock) {
  491. state |= set;
  492. }
  493. }
  494. private void clr_state(ThreadState clr) {
  495. lock(synch_lock) {
  496. state &= ~clr;
  497. }
  498. }
  499. #if NET_1_1
  500. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  501. extern public static byte VolatileRead (ref byte address);
  502. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  503. extern public static double VolatileRead (ref double address);
  504. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  505. extern public static short VolatileRead (ref short address);
  506. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  507. extern public static int VolatileRead (ref int address);
  508. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  509. extern public static long VolatileRead (ref long address);
  510. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  511. extern public static IntPtr VolatileRead (ref IntPtr address);
  512. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  513. extern public static object VolatileRead (ref object address);
  514. [CLSCompliant(false)]
  515. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  516. extern public static sbyte VolatileRead (ref sbyte address);
  517. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  518. extern public static float VolatileRead (ref float address);
  519. [CLSCompliant (false)]
  520. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  521. extern public static ushort VolatileRead (ref ushort address);
  522. [CLSCompliant (false)]
  523. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  524. extern public static uint VolatileRead (ref uint address);
  525. [CLSCompliant (false)]
  526. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  527. extern public static ulong VolatileRead (ref ulong address);
  528. [CLSCompliant (false)]
  529. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  530. extern public static UIntPtr VolatileRead (ref UIntPtr address);
  531. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  532. extern public static void VolatileWrite (ref byte address, byte value);
  533. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  534. extern public static void VolatileWrite (ref double address, double value);
  535. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  536. extern public static void VolatileWrite (ref short address, short value);
  537. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  538. extern public static void VolatileWrite (ref int address, int value);
  539. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  540. extern public static void VolatileWrite (ref long address, long value);
  541. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  542. extern public static void VolatileWrite (ref IntPtr address, IntPtr value);
  543. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  544. extern public static void VolatileWrite (ref object address, object value);
  545. [CLSCompliant(false)]
  546. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  547. extern public static void VolatileWrite (ref sbyte address, sbyte value);
  548. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  549. extern public static void VolatileWrite (ref float address, float value);
  550. [CLSCompliant (false)]
  551. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  552. extern public static void VolatileWrite (ref ushort address, ushort value);
  553. [CLSCompliant (false)]
  554. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  555. extern public static void VolatileWrite (ref uint address, uint value);
  556. [CLSCompliant (false)]
  557. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  558. extern public static void VolatileWrite (ref ulong address, ulong value);
  559. [CLSCompliant (false)]
  560. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  561. extern public static void VolatileWrite (ref UIntPtr address, UIntPtr value);
  562. #endif
  563. #if NET_2_0
  564. [MonoTODO ("stack size is ignored")]
  565. public Thread (ThreadStart start, int maxStackSize)
  566. {
  567. if (start == null)
  568. throw new ArgumentNullException ("start");
  569. if (maxStackSize < 131072)
  570. throw new ArgumentException ("< 128 kb", "maxStackSize");
  571. threadstart=start;
  572. }
  573. [MonoTODO]
  574. public Thread (ParameterizedThreadStart start)
  575. {
  576. if (start == null)
  577. throw new ArgumentNullException ("start");
  578. throw new NotImplementedException ();
  579. }
  580. [MonoTODO]
  581. public Thread (ParameterizedThreadStart start, int maxStackSize)
  582. {
  583. if (start == null)
  584. throw new ArgumentNullException ("start");
  585. if (maxStackSize < 131072)
  586. throw new ArgumentException ("< 128 kb", "maxStackSize");
  587. throw new NotImplementedException ();
  588. }
  589. [MonoTODO]
  590. public ExecutionContext ExecutionContext {
  591. [ReliabilityContract (Consistency.WillNotCorruptState, CER.MayFail)]
  592. get { throw new NotImplementedException (); }
  593. }
  594. public int ManagedThreadId {
  595. get { return thread_id; }
  596. }
  597. [MonoTODO]
  598. [ReliabilityContract (Consistency.WillNotCorruptState, CER.MayFail)]
  599. public static void BeginCriticalRegion ()
  600. {
  601. throw new NotImplementedException ();
  602. }
  603. [MonoTODO]
  604. [ReliabilityContract (Consistency.WillNotCorruptState, CER.Success)]
  605. public static void EndCriticalRegion ()
  606. {
  607. throw new NotImplementedException ();
  608. }
  609. [MonoTODO]
  610. public static void BeginThreadAffinity ()
  611. {
  612. throw new NotImplementedException ();
  613. }
  614. [MonoTODO]
  615. public static void EndThreadAffinity ()
  616. {
  617. throw new NotImplementedException ();
  618. }
  619. [MonoTODO]
  620. public ApartmentState GetApartmentState ()
  621. {
  622. return this.ApartmentState;
  623. }
  624. [MonoTODO]
  625. public void SetApartmentState (ApartmentState state)
  626. {
  627. this.ApartmentState = state;
  628. }
  629. [MonoTODO]
  630. public bool TrySetApartmentState (ApartmentState state)
  631. {
  632. try {
  633. this.ApartmentState = state;
  634. return true;
  635. }
  636. catch (ArgumentException) {
  637. throw;
  638. }
  639. catch {
  640. return false;
  641. }
  642. }
  643. [MonoTODO]
  644. public CompressedStack GetCompressedStack ()
  645. {
  646. throw new NotImplementedException ();
  647. }
  648. [MonoTODO]
  649. public void SetCompressedStack (CompressedStack stack)
  650. {
  651. throw new NotImplementedException ();
  652. }
  653. [ComVisible (false)]
  654. public override int GetHashCode ()
  655. {
  656. // ??? overridden but not guaranteed to be unique ???
  657. return thread_id;
  658. }
  659. [MonoTODO]
  660. public void Start (object parameter)
  661. {
  662. throw new NotImplementedException ();
  663. }
  664. #endif
  665. }
  666. }