|
|
Home » U++ Library support » U++ MT-multithreading and servers » Threading example for U++
|
Re: Threading example for U++ [message #10294 is a reply to message #10199] |
Sat, 30 June 2007 12:48   |
|
I bit extened:
- More factal sets
- Logarythmic color scale
- one rendering method for all fractals
- fractal calculating methods are callbacks for thread rendering methods
- left down + mouse move , moves the fractal
- left down + CTRL + mouse move selects area for zoom
- axis describing complex area
[Updated on: Sun, 08 July 2007 01:13] Report message to a moderator
|
|
|
|
|
Re: Threading example for U++ [message #10301 is a reply to message #10299] |
Sat, 30 June 2007 18:26   |
|
[quote title=luzr wrote on Sat, 30 June 2007 18:09]BUG: When moving the area, if you move the mouse outside the view, it gets "stuck" and continues moving even if mouse button is released...
Instead of 'moving' flag, use SetCapture and IsCapture.
[/quote
I check this out.
[quote]
You might also try to make the program structure a little bit less complex, I have noticed the troubles you have with routing mouse messages.
[/quote]
I don't have troubles, i jut follow familiar for me .NET rules of connecting events, and similar to Qt. Control got events which can be connected, thats all.
I didn't use such techniques of letting sub control owning entire window. It don't looks good for me.
Control owns window, window contains control which contains this window. Circular dependency ?
What in case when window got multiple controls and we want to connect many events ?
[Updated on: Sat, 30 June 2007 18:27] Report message to a moderator
|
|
|
Re: Threading example for U++ [message #10302 is a reply to message #10301] |
Sat, 30 June 2007 20:17   |
 |
mirek
Messages: 13891 Registered: November 2005
|
Ultimate Member |
|
|
Quote: |
Quote: |
You might also try to make the program structure a little bit less complex, I have noticed the troubles you have with routing mouse messages.
|
I don't have troubles, i jut follow familiar for me .NET rules of connecting events, and similar to Qt. Control got events which can be connected, thats all.
I didn't use such techniques of letting sub control owning entire window. It don't looks good for me.
|
That is just mind barrier, believe me. The key to understand is that class containment does not have to be related to the GUI containment.
Quote: |
Control owns window, window contains control which contains this window. Circular dependency ?
What in case when window got multiple controls and we want to connect many events ?
|
I think "got" is a wrong word here.... Sure, nothing prevents you to follow GUI in class composition, but in U++ it is not requirement.
Before going deep into philosophic details, "inverse layout" in your example would very likely produce much less complex code - which is the thing I am usually pursuing...
|
|
|
|
|
|
|
|
|
Re: Threading example for U++ [message #10574 is a reply to message #10416] |
Tue, 17 July 2007 03:40   |
nixnixnix
Messages: 415 Registered: February 2007 Location: Kelowna, British Columbia
|
Senior Member |
|
|
should this code compile on a default install of 2007.1 under windows?
I get
----- plugin\z ( GUI MT GCC FORCE_SPEED BLITZ WIN32 ) (7 / 9)
adler32.c
plugin/bmp: 4 file(s) built in (0:01.67), 417 msecs / file, duration = 3500 msecs, parallelization 100%
compress.c
crc32.c
deflate.c
gzio.c
infblock.c
infcodes.c
inffast.c
inflate.c
inftrees.c
infutil.c
trees.c
uncompr.c
zutil.c
----- plugin\png ( GUI MT GCC FORCE_SPEED BLITZ WIN32 ) (8 / 9)
pnglib.c
plugin\z: 14 file(s) built in (0:01.26), 90 msecs / file, duration = 3954 msecs, parallelization 100%
pngupp.cpp
pngreg.icpp
----- ThrFractRend ( GUI MT MAIN GCC FORCE_SPEED BLITZ WIN32 ) (9 / 9)
BLITZ: ThrFractRend_design.cpp ThrFractRend_sse2.cpp ThrFractRend.cpp main.cpp Paintbox.cpp
plugin\png: 3 file(s) built in (0:04.26), 1420 msecs / file, duration = 8781 msecs, parallelization 100%
Core: 36 file(s) built in (0:11.13), 309 msecs / file, duration = 30922 msecs, parallelization 100%
In file included from C:\MyApps\ThrFractRend\ThrFractRend_design.cpp:42,
from C:/upp/out/ThrFractRend/MINGW.Blitz.Force_speed.Gui.Main.Mt\ $blitz.cpp:3:
C:\MyApps\ThrFractRend\/ThrFractRend.h:84: error: `Mutex' does not name a type
C:\MyApps\ThrFractRend\/ThrFractRend.h:85: error: `Mutex' does not name a type
In file included from C:/upp/out/ThrFractRend/MINGW.Blitz.Force_speed.Gui.Main.Mt\ $blitz.cpp:10:
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp: In member function `void mtfr::Threads::FnMandelbrot(const mtfr::ComplexD&, unsigned int*) const':
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:51: error: `__m128d' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:51: error: (Each undeclared identifier is reported only once for each function it appears in.)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:51: error: expected `;' before "C0"
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:54: error: `C4' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:54: error: `_mm_set1_pd' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:55: error: `C0' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:55: error: `_mm_setr_pd' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:57: error: `X0' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:60: error: `X1' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:60: error: `_mm_mul_pd' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:61: error: `X2' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:61: error: `_mm_unpackhi_pd' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:62: error: `X3' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:62: error: `_mm_add_sd' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:63: error: `_mm_comigt_sd' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:66: error: `X4' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:69: error: `_mm_sub_sd' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:71: error: `_mm_mul_sd' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:75: error: `_mm_unpacklo_pd' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:76: error: `_mm_add_pd' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp: In member function `void mtfr::Threads::FnJulia(const mtfr::ComplexD&, unsigned int*) const':
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:85: error: `__m128d' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:85: error: expected `;' before "C0"
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:88: error: `C4' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:88: error: `_mm_set1_pd' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:89: error: `C0' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:89: error: `_mm_setr_pd' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:90: error: `X0' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:94: error: `X1' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:94: error: `_mm_mul_pd' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:95: error: `X2' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:95: error: `_mm_unpackhi_pd' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:96: error: `X3' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:96: error: `_mm_add_sd' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:97: error: `_mm_comigt_sd' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:100: error: `X4' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:103: error: `_mm_sub_sd' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:105: error: `_mm_mul_sd' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:109: error: `_mm_unpacklo_pd' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend_sse2.cpp:110: error: `_mm_add_pd' undeclared (first use this function)
In file included from C:/upp/out/ThrFractRend/MINGW.Blitz.Force_speed.Gui.Main.Mt\ $blitz.cpp:14:
C:\MyApps\ThrFractRend\ThrFractRend.cpp: In member function `void mtfr::Threads::picbox_Paint(Upp::Draw&)':
C:\MyApps\ThrFractRend\ThrFractRend.cpp:82: error: `job_lock' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend.cpp:93: error: `image_lock' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend.cpp: In member function `void mtfr::Threads::ThreadRenderJob(int, int, const Upp::Callback2<const mtfr::ComplexD&, unsigned int*>&, int)':
C:\MyApps\ThrFractRend\ThrFractRend.cpp:131: error: `job_lock' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend.cpp:133: error: `image_lock' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend.cpp:135: error: no matching function for call to `Upp::Semaphore::Release()'
C:/upp/uppsrc/Core/Thread.h:70: note: candidates are: void Upp::Semaphore::Release(int)
C:\MyApps\ThrFractRend\ThrFractRend.cpp: In member function `void mtfr::Threads::Process(const Upp::Callback2<const mtfr::ComplexD&, unsigned int*>&)':
C:\MyApps\ThrFractRend\ThrFractRend.cpp:197: error: `callback4' undeclared (first use this function)
C:\MyApps\ThrFractRend\ThrFractRend.cpp:199: error: `job_lock' undeclared (first use this function)
ThrFractRend: 5 file(s) built in (0:02.48), 496 msecs / file, duration = 4031 msecs, parallelization 16%
There were errors. (1:15.50)
nick
[Updated on: Tue, 17 July 2007 03:42] Report message to a moderator
|
|
|
|
|
|
|
Re: Threading example for U++ [message #10977 is a reply to message #10964] |
Wed, 08 August 2007 23:38   |
|
1.Terminating - wrong idea (becouse of allocated resources by threads)
Telling thread to stop via some variable - is good idea
2. Comunicating betwen threads for example with ThreadSafeQueue
when one thread do somting for other thread
Will think about changing the example in the future for use with ThreadSafeQueue...
|
|
|
|
Re: Threading example for U++ [message #10985 is a reply to message #10979] |
Thu, 09 August 2007 21:59   |
|
I will put here my fresh one hoever this [C++] implementation is not tested, but Same Generic in C# works well.
[Im at porting stage of some app to c++ so why it is stil not tested]
template <typename T>
class ThreadSafeQueue
{
class QueueElement;
public :
int GetCount() const;
void Enqueue(T value);
T Dequeue();
void FinishWaiting(bool end_job);
ThreadSafeQueue();
~ThreadSafeQueue();
private:
int m_count;
QueueElement * m_head;
QueueElement * m_tail;
Threading::Monitor m_monitor;
Threading::CriticalSection m_lock;
bool m_finish_wait;
class QueueElement
{
private:
friend class ThreadSafeQueue;
T m_value;
QueueElement * m_next;
T GetValue() const;
QueueElement(const T & value);
};
};
template <typename T>
int ThreadSafeQueue<T>::GetCount() const
{
return this->m_count;
}
template <typename T>
ThreadSafeQueue<T>::ThreadSafeQueue()
: m_head(NULL)
, m_finish_wait(false)
, m_tail(NULL)
, m_count(0)
{}
template <typename T>
ThreadSafeQueue<T>::~ThreadSafeQueue()
{
m_lock.Enter();
//Clenup remaining items
if (this->m_head != NULL)
{
QueueElement *p = this->m_head, *pdel;
while (p != NULL)
{
pdel = p;
p = p->m_next;
delete pdel;
}
this->m_head = NULL;
this->m_tail = NULL;
}
m_lock.Leave();
}
template <typename T>
void ThreadSafeQueue<T>::Enqueue(T value)
{
m_lock.Enter();
{
m_count++;
QueueElement *enqueue = new QueueElement(value);
if (m_head == NULL)
{
m_head = enqueue;
m_monitor.Pulse();
}
else
m_tail->m_next = enqueue;
m_tail = enqueue;
}
m_lock.Leave();
}
template <typename T>
T ThreadSafeQueue<T>::Dequeue()
{
QueueElement *dequeued;
m_lock.Enter();
{
while (m_head == NULL && !m_finish_wait)
m_monitor.Wait();
if (m_head == NULL && m_finish_wait)
{
m_lock.Leave();
return T(); //End
}
m_count--;
dequeued = m_head;
m_head = m_head->m_next;
}
m_lock.Leave();
T res(dequeued->GetValue());
delete dequeued;
return res;
}
template <typename T>
void ThreadSafeQueue<T>::FinishWaiting(bool end_job)
{
m_lock.Enter();
{
m_finish_wait = end_job;
m_monitor.Pulse();
}
m_lock.Leave();
}
template <typename T>
ThreadSafeQueue<T>::QueueElement::QueueElement(const T & value)
: m_next(NULL)
, m_value(value)
{}
template <typename T>
T ThreadSafeQueue<T>::QueueElement::GetValue() const
{
return this->m_value;
}
class Monitor : public CriticalSection
{
public:
Monitor();
void Wait() throw(...);
void Pulse() throw(...);
private:
int m_QueueSize;
CriticalSection m_lock;
Semaphore m_waiting;
};
Monitor::Monitor() : m_QueueSize(0) {}
void Monitor::Wait()
{
m_lock.Enter();
m_QueueSize++;
m_lock.Leave();
m_waiting.Wait();
}
void Monitor::Pulse()
{
m_lock.Enter();
if (m_QueueSize > 0)
m_waiting.Release();
m_lock.Leave();
}
|
|
|
Goto Forum:
Current Time: Mon May 29 06:51:44 CEST 2023
Total time taken to generate the page: 0.01459 seconds
|
|
|