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 » Interprocess communication with U++
Interprocess communication with U++ [message #16051] Sun, 25 May 2008 20:27 Go to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 916
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

Are there any classes to help making interprocess communication?
Maybe something like Windows` named kernel objects.

For example, I`m updating a number of files and I want other copies of my process to wait for i/o operations to complete. Is there anything in U++ to help me with?
Re: Interprocess communication with U++ [message #16056 is a reply to message #16051] Mon, 26 May 2008 08:47 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 916
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

I`ve discovered that both Windows and UNIX standards support named semaprhores. So the existing Semaphore class could be extended towards the named semaphores.

Research continues.
Re: Interprocess communication with U++ [message #16057 is a reply to message #16056] Mon, 26 May 2008 09:16 Go to previous message
Mindtraveller is currently offline  Mindtraveller
Messages: 916
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

OK, patch seemes to be trivial.
Here is what I propose:

Mt.h:
class Semaphore {
#ifdef PLATFORM_WIN32
	HANDLE     handle;
#else
	sem_t      sem;
	sem_t     *namedSem;
#endif

public:
	void       Wait();
	void       Release();

	Semaphore();
	Semaphore(const char *name);
	~Semaphore();
}; 


Win32:
void Semaphore::Release()
{
	ReleaseSemaphore(handle, 1, NULL);
}

void Semaphore::Wait()
{
	WaitForSingleObject(handle, INFINITE);
}

Semaphore::Semaphore()
{
	handle = CreateSemaphore(NULL, 0, INT_MAX, NULL);
}

Semaphore::Semaphore(const char *name)
{
	handle = CreateSemaphore(NULL, 0, INT_MAX, name);
}

Semaphore::~Semaphore()
{
	CloseHandle(handle);
}


POSIX:
void Semaphore::Wait()
{
	namedSem ? sem_wait(namedSem) : sem_wait(&sem);
}

Semaphore::Semaphore()
	:namedSem(NULL)

{
	sem_init(&sem, 0, 0);
}

Semaphore::Semaphore(const char *name)
{
	namedSem = sem_open(name, O_CREAT);
}

Semaphore::~Semaphore()
{
	namedSem ? sem_close(namedSem) : sem_destroy(&sem);
}


Didn`t have opportunity to test on Linux.
Previous Topic: PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP not defined
Next Topic: WaitForMultipleObjects() analog?
Goto Forum:
  


Current Time: Mon Oct 21 01:41:40 CEST 2019

Total time taken to generate the page: 0.03305 seconds