diff options
author | Thomas Grill <xovo@users.sourceforge.net> | 2002-10-22 23:07:10 +0000 |
---|---|---|
committer | Thomas Grill <xovo@users.sourceforge.net> | 2002-10-22 23:07:10 +0000 |
commit | d62e56f4df9594f72ce501f5e19c974fd18e7295 (patch) | |
tree | 635d4af7a7c2425098e60ca277086ec436b617f7 /externals/grill/flext/tutorial/thread2 | |
parent | c6f373c281ecb5cd1f4aa7a070e15cc61ab8793c (diff) |
This commit was generated by cvs2svn to compensate for changes in r186,
which included commits to RCS files with non-trunk default branches.
svn path=/trunk/; revision=187
Diffstat (limited to 'externals/grill/flext/tutorial/thread2')
-rw-r--r-- | externals/grill/flext/tutorial/thread2/main.cpp | 132 | ||||
-rwxr-xr-x | externals/grill/flext/tutorial/thread2/thread2.cw | bin | 0 -> 89119 bytes | |||
-rw-r--r-- | externals/grill/flext/tutorial/thread2/thread2.dsp | 95 |
3 files changed, 227 insertions, 0 deletions
diff --git a/externals/grill/flext/tutorial/thread2/main.cpp b/externals/grill/flext/tutorial/thread2/main.cpp new file mode 100644 index 00000000..ce2a170e --- /dev/null +++ b/externals/grill/flext/tutorial/thread2/main.cpp @@ -0,0 +1,132 @@ +/* +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 +*/ + +// define FLEXT_THREADS for thread usage. Flext must also have been compiled with that defined! +#ifndef FLEXT_THREADS +#define FLEXT_THREADS +#endif + +#include <flext.h> + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 301) +#error You need at least flext version 0.3.1 +#endif + + +class thread2: + public flext_base +{ + FLEXT_HEADER(thread2,flext_base) + +public: + thread2(int del); + +protected: + void m_start(int st); + void m_stop(); + void m_text(); + + void m_textout(); + +private: + FLEXT_THREAD_I(m_start); // define threaded callback for method m_start + FLEXT_CALLBACK(m_stop); // normal callback for m_stop + FLEXT_CALLBACK(m_text); // turn on console output + + FLEXT_THREAD(m_textout); // text output + + float delay; + volatile int count; + + // caution: CodeWarrior seems to ignore volatile modifier!! + volatile bool stopit,running,blipping; // flags for running and stopping + + // thread conditional for stop signal + ThrCond cond; +}; + +FLEXT_NEW_1("thread2",thread2,int) + + + +thread2::thread2(int del): + delay(del/1000.f), + stopit(false), + running(false),blipping(false) +{ + AddInAnything(); + AddOutInt(2); + SetupInOut(); // set up inlets and outlets + + FLEXT_ADDMETHOD(0,m_start); // register start for integer numbers (floats in PD) + FLEXT_ADDMETHOD_(0,"text",m_text); // register m_text method for "text" tag + FLEXT_ADDMETHOD_(0,"stop",m_stop); // register m_text method for "stop" tag +} + +void thread2::m_start(int st) +{ + // if already running, just set back the counter + if(running) { count = st; return; } + + running = true; + + // loop until either the system exit flag or the "stopit" flag is set + for(count = st; !ShouldExit() && !stopit; ++count) + { + Sleep(delay); + ToOutInt(0,count); // output loop count + } + + cond.Lock(); // lock conditional + running = false; // change state flag + cond.Signal(); // signal changed flag to watiting "stop" method + cond.Unlock(); // unlock conditional +} + +void thread2::m_stop() +{ + cond.Lock(); // lock conditional + stopit = true; // set termination flag + + while(*(&running) || *(&blipping)) // workaround for CodeWarrior! + { + cond.Wait(); // wait for signal by running threads + } + + // --- Here, the threads should have stopped --- + + stopit = false; // reset flag + cond.Unlock(); // unlock conditional +} + + +void thread2::m_text() +{ + FLEXT_CALLMETHOD(m_textout); +} + +void thread2::m_textout() +{ + if(blipping) return; + blipping = true; + + while(!ShouldExit() && !stopit) { + post("%i",count); + Sleep(1.f); + } + + cond.Lock(); // lock conditional + blipping = false; // change state flag + cond.Signal(); // signal changed flag to watiting "stop" method + cond.Unlock(); // unlock conditional +} + diff --git a/externals/grill/flext/tutorial/thread2/thread2.cw b/externals/grill/flext/tutorial/thread2/thread2.cw Binary files differnew file mode 100755 index 00000000..b26ff18b --- /dev/null +++ b/externals/grill/flext/tutorial/thread2/thread2.cw diff --git a/externals/grill/flext/tutorial/thread2/thread2.dsp b/externals/grill/flext/tutorial/thread2/thread2.dsp new file mode 100644 index 00000000..da5e149e --- /dev/null +++ b/externals/grill/flext/tutorial/thread2/thread2.dsp @@ -0,0 +1,95 @@ +# Microsoft Developer Studio Project File - Name="thread2" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=thread2 - Win32 Debug +!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE +!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl +!MESSAGE +!MESSAGE NMAKE /f "thread2.mak". +!MESSAGE +!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben +!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel: +!MESSAGE +!MESSAGE NMAKE /f "thread2.mak" CFG="thread2 - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "thread2 - Win32 Release" (basierend auf "Win32 (x86) Dynamic-Link Library") +!MESSAGE "thread2 - Win32 Debug" (basierend auf "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "max/flext/tutorial/thread2" +# PROP Scc_LocalPath "." +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "thread2 - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "msvc" +# PROP Intermediate_Dir "msvc" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GR- /GX- /O2 /I "..\..\source" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "NT" /D "PD" /D "FLEXT_THREADS" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0xc07 /d "NDEBUG" +# ADD RSC /l 0xc07 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib /nologo /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib pd.lib flext_t-pdwin.lib pthreadVC.lib /nologo /dll /machine:I386 /out:"../msvc/thread2.dll" /libpath:"..\..\pd-msvc" + +!ELSEIF "$(CFG)" == "thread2 - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "msvc-debug" +# PROP Intermediate_Dir "msvc-debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GR- /GX- /ZI /Od /I "..\..\source" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "NT" /D "PD" /D "FLEXT_THREADS" /FR /YX /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0xc07 /d "_DEBUG" +# ADD RSC /l 0xc07 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib pd.lib flext_td-pdwin.lib pthreadVC.lib /nologo /dll /debug /machine:I386 /pdbtype:sept /libpath:"..\..\pd-msvc" + +!ENDIF + +# Begin Target + +# Name "thread2 - Win32 Release" +# Name "thread2 - Win32 Debug" +# Begin Source File + +SOURCE=.\main.cpp +# End Source File +# End Target +# End Project |