X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f From: "Lawrence Rust" Newsgroups: comp.os.msdos.djgpp Subject: Re: Task switch with SIGALRM Date: Mon, 17 May 2004 16:44:23 +0200 Organization: Software Systems Lines: 39 Message-ID: References: NNTP-Posting-Host: mix-poitiers-105-3-86.w193-250.abo.wanadoo.fr X-Trace: news-reader4.wanadoo.fr 1084806179 13905 193.250.33.86 (17 May 2004 15:02:59 GMT) X-Complaints-To: abuse AT wanadoo DOT fr NNTP-Posting-Date: 17 May 2004 15:02:59 GMT X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4927.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4927.1200 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Gabriel Zoltan wrote... > Hi! > > Thanks for the code you provided. I'm going to try to use setjmp/longjmp. > The only thing I don't understand is how you set up the jmp_buf structure > initially. How do I run a task for the first time? Could someone please > explain it? (Sadly I'm quite in a rush for trial&error.) Thanks in > advance. The jmp_buf is setup by the call to setjmp in MTC_PlatformThreadAlloc(). So using the code snippet that I posted you would do something like: struct MTC_Thread* pMain; struct MTC_Thread* pThread; /* Create the main thread */ pMain = MTC_PlatformThreadAlloc( 1); /* Create worker thread */ pThread = MTC_PlatformThreadAlloc( 0); /* This init's the jmp_buf */ /* Switch to worker. * This saves main's state in pMain->jbuf and jumps to the point * saved in pThread->jbuf i.e. just after the call to setjmp() in * MTC_PlatformThreadAlloc() but using the worker's stack. The * worker then calls MTC_ThreadExecute() which would call a thread * specific main function. */ PlatformThreadSwitch( &pMain->thread, &pThread->thread); NB The functions shown were intended to be called from a platform independent scheduler so they don't show how to setup the thread's main function and how to manage which thread to dispatch, say from your signal handler. -- Lawrence Rust, Software Systems, www.softsystem.co.uk