Commit 9e66fd07 authored by thomas's avatar thomas
Browse files

no message


git-svn-id: https://svn.grrrr.org/ext/trunk@184 4d9ac71a-51e6-0310-8455-cad1006bcd31
parent 9ef50f77
......@@ -175,7 +175,7 @@ general:
bugs:
- PD: problems with timed buffer redrawing (takes a lot of cpu time)
- introduce timed thread termination upon object destruction
- hard thread termination upon object destruction doesn't seem to work properly
tests:
- PD: figure out what "pointer" messages do and where they occur
......
......@@ -152,6 +152,7 @@ flext_base::~flext_base()
// wait for thread termination
shouldexit = true;
for(int wi = 0; thrhead && wi < 100; ++wi) Sleep(0.01f);
qmutex.Lock(); // Lock message queue
tlmutex.Lock();
// timeout -> hard termination
while(thrhead) {
......@@ -161,7 +162,9 @@ flext_base::~flext_base()
t->nxt = NULL; delete t;
}
tlmutex.Unlock();
qmutex.Unlock();
// send remaining pending messages
while(qhead) QTick(this);
clock_free(qclk);
#endif
......
......@@ -51,7 +51,7 @@ void flext_base::PopThread()
if(prv)
prv->nxt = ti->nxt;
else
thrhead = thrtail = ti;
thrhead = thrtail = ti->nxt;
ti->nxt = NULL;
delete ti;
}
......
#N canvas 385 346 454 304 12;
#X floatatom 54 200 5 0 0;
#X floatatom 188 200 5 0 0;
#X msg 46 131 2;
#X msg 91 131 stop;
#X msg 184 132 2;
#X msg 229 132 stop;
#X obj 100 44 bng 25 250 50 0 empty empty empty 0 -6 0 8 -258699 -1
-1;
#X obj 192 44 bng 25 250 50 0 empty empty empty 0 -6 0 8 -258699 -1
-1;
#X text 92 23 start;
#X text 184 22 stop;
#X obj 53 167 thread2 10 aaa;
#X obj 187 167 thread2 100 bbb;
#X connect 2 0 10 0;
#X connect 3 0 10 0;
#X connect 4 0 11 0;
#X connect 5 0 11 0;
#X connect 6 0 2 0;
#X connect 6 0 4 0;
#X connect 7 0 3 0;
#X connect 7 0 5 0;
#X connect 10 0 0 0;
#X connect 11 0 1 0;
/*
flext tutorial - threads 2
Copyright (c) 2002 Thomas Grill (xovo@gmx.net)
For information on usage and redistribution, and for a DISCLAIMER OF ALL
WARRANTIES, see the file, "license.txt," in this distribution.
-------------------------------------------------------------------------
This shows an example of multiple threads and syncing with a thread conditional
*/
#include <flext.h>
#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 300)
#error You need at least flext version 0.3.0
#endif
class thread2:
public flext_base
{
FLEXT_HEADER(thread2,flext_base)
public:
thread2(int del,t_symptr txt);
protected:
void m_start(int st);
void m_stop();
void m_blip();
private:
FLEXT_THREAD_I(m_start); // define threaded callback for method m_start
FLEXT_CALLBACK(m_stop); // normal callback for m_stop
FLEXT_THREAD(m_blip); // define threaded callback for method m_blip
float delay;
bool stopit,running,blipping;
int count;
t_symbol *bliptxt;
ThrCond cond;
};
FLEXT_NEW_2("thread2",thread2,int,t_symptr)
thread2::thread2(int del,t_symptr txt):
delay(del/1000.f),
bliptxt(txt),
stopit(false),
running(false),blipping(false)
{
AddInAnything();
AddOutAnything();
SetupInOut(); // set up inlets and outlets
FLEXT_ADDMETHOD(0,m_start);
FLEXT_ADDMETHOD_(0,"stop",m_stop);
}
void thread2::m_start(int st)
{
if(running) { count = st; return; }
running = true;
FLEXT_CALLMETHOD(m_blip);
for(count = st; !ShouldExit() && !stopit; ++count)
{
Sleep(delay);
ToOutInt(0,count);
}
cond.Lock();
running = false;
cond.Signal();
cond.Unlock();
}
void thread2::m_stop()
{
cond.Lock();
stopit = true;
while(running || blipping) cond.Wait();
stopit = false;
cond.Unlock();
}
void thread2::m_blip()
{
blipping = true;
while(!ShouldExit() && !stopit) {
post(const_cast<char *>(GetString(bliptxt)));
Sleep(0.1f);
}
cond.Lock();
blipping = false;
cond.Signal();
cond.Unlock();
}
\ No newline at end of file
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELSCHT WERDEN!
###############################################################################
Project: "thread2"=.\thread2\thread2.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment