Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ MT-multithreading and servers » Skylark and GUI in one app - need some advices
Re: Skylark and GUI in one app - need some advices [message #39787 is a reply to message #39771] Sat, 27 April 2013 22:05 Go to previous message
Zbych is currently offline  Zbych
Messages: 326
Registered: July 2009
Senior Member
It is possible to close Skylark nicely, but it requires some changes. This post can give you some clues.

1. You need to add Quit() public method to Skylark:
void SkylarkApp::Quit()
{
	quit = true;
#ifdef PLATFORM_POSIX
	Broadcast(SIGTERM);
#endif
	TcpSocket s;
	s.Timeout(100);
	s.Connect("127.0.0.1", port);
}


2. Main() also requires some changes, because it waits for all threads in your application to shutdown. If Skylark is run from another thread it will wait for itself in endless loop.
After this change it will wait only for it's own threads:
void SkylarkApp::Main()
{
	Buffer<Thread> uwt(threads);
	for(int i = 0; i < threads; i++)
		uwt[i].Run(THISBACK(ThreadRun));
	
	/* Wait for threads to shut down */
	for (int i = 0; i < threads; i++)
		uwt[i].Wait();
}


3. If you need to wait for Skylark to shutdown you should use Run and Wait methods instead of Start:
class MyApp: public Skylark{

    Thread th;

    void Start() {th.Run(THISBACK(Run));}

    void Stop() {Quit(); th.Wait();}
}


4. If you need to pass data to skylark handlers via global variables, you should disable forking and use atomic types or mutexes, to protect data integrity.


Mirek, what do you think about those changes (1 & 2)?


[Updated on: Sat, 27 April 2013 22:13]

Report message to a moderator

 
Read Message
Read Message
Previous Topic: Skylark OO (reposted from PM)
Next Topic: How to close Skylark server except using Ctrl+C
Goto Forum:
  


Current Time: Fri May 10 03:39:35 CEST 2024

Total time taken to generate the page: 0.02246 seconds