[omniORB] omnithreads/semaphore problem on WinNT 4.0

Georg Weissenbacher georg.weissenbacher@gmx.at
Tue, 15 Aug 2000 18:12:39 +0200


Hi,
I've a problems with omnithreads under WinNT 4.0. I'm using version
2.8 of omniORB2 and the omnithreads library that is shipped with the
orb. I've compiled the ORB and the thread library on Linux
(Debian libc2.0, Mandrake libc2.1) and on WinNT 4.0 using VC++ 6.0.
On Windows I'm linking with omnithread2_rt.lib.

My problem:
Following program produces the output

Hello world!!! 

on all the Unix platforms, but it produces 

Hello !!!

on WinNT 4.0 and hangs afterwards (join). It terminates, if I
leave out the call to join, but it still doesn't print the
"world" string :(

Is this a common problem or have I done something wrong?

thx,
Georg Weissenbacher

#include <stdio.h>
#include <omnithread.h>

class UserThread: public omni_thread
{
protected:
	omni_condition* _sem;
public:
	UserThread (omni_condition* sem);
private:
	void* run_undetached (void* arg);
};

UserThread::UserThread (omni_condition* sem): omni_thread (), _sem (sem)
{
	start_undetached ();
}

void* UserThread::run_undetached (void *arg)
{
	printf ("Hello ");
	_sem->wait ();
	printf ("world");
	return 0;
}

int main (int argc, char** argv)
{
	omni_mutex* lock = new omni_mutex ();
	omni_condition* semaphore = new omni_condition (lock);

	UserThread* thread = new UserThread (semaphore);

	omni_thread::sleep (1, 0);
	semaphore->broadcast ();
	omni_thread::yield ();
	omni_thread::sleep (1, 0);

	printf ("!!!\n");

	thread->join (0);

	return 0;
}