From 0724f87d201a8ada26e35cd976f05ef1bb879431 Mon Sep 17 00:00:00 2001 From: cxl Date: Sat, 16 May 2009 16:50:50 +0000 Subject: [PATCH] reference: Ctrl::Lock example git-svn-id: svn://ultimatepp.org/upp/trunk@1191 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- reference/GuiMT_Lock/GuiMT_Lock.upp | 11 +++++++ reference/GuiMT_Lock/init | 4 +++ reference/GuiMT_Lock/main.cpp | 47 +++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 reference/GuiMT_Lock/GuiMT_Lock.upp create mode 100644 reference/GuiMT_Lock/init create mode 100644 reference/GuiMT_Lock/main.cpp diff --git a/reference/GuiMT_Lock/GuiMT_Lock.upp b/reference/GuiMT_Lock/GuiMT_Lock.upp new file mode 100644 index 000000000..9b4bb9465 --- /dev/null +++ b/reference/GuiMT_Lock/GuiMT_Lock.upp @@ -0,0 +1,11 @@ +description "This package demonstrates the use of Ctrl::Lock in MT applications\377"; + +uses + CtrlLib; + +file + main.cpp; + +mainconfig + "" = "GUI MT"; + diff --git a/reference/GuiMT_Lock/init b/reference/GuiMT_Lock/init new file mode 100644 index 000000000..4d8f059f5 --- /dev/null +++ b/reference/GuiMT_Lock/init @@ -0,0 +1,4 @@ +#ifndef _GuiLock_icpp_init_stub +#define _GuiLock_icpp_init_stub +#include "CtrlLib/init" +#endif diff --git a/reference/GuiMT_Lock/main.cpp b/reference/GuiMT_Lock/main.cpp new file mode 100644 index 000000000..7568ed7c6 --- /dev/null +++ b/reference/GuiMT_Lock/main.cpp @@ -0,0 +1,47 @@ +#include + +using namespace Upp; + +struct App : TopWindow { + Thread work; + + void Work(); + + ArrayCtrl list; + + typedef App CLASSNAME; + + App(); + ~App(); +}; + +void App::Work() +{ + int q = 0; + while(!Thread::IsShutdownThreads()) { + for(int i = 0; i < 100; i++) { + Ctrl::Lock __(list); + list.Set(i, 0, (int64)Random()); + } + Sleep(10); + } +} + +App::App() +{ + list.AddColumn("Test"); + Add(list.SizePos()); + work.Run(THISBACK(Work)); +} + +App::~App() +{ + Thread::ShutdownThreads(); + work.Wait(); +} + +GUI_APP_MAIN +{ + App app; + app.Run(); +}