guy keren wrote: > On Thu, 1 Apr 1999, Daniel Feiglin wrote: > > > I'm rather busily tring to find my feet in Linux from OS/2 Warp 4. I just > > wrote a samll c server / Java client on Warp, using tcp/ip domain sockets. The > > c programme has (for now) one thread. The main programme creates an event > > semaphore and does a _beginthread(). It posts the semaphore after getting "the > > nod" from the Java client. The thread then does its stuff, resets the > > semaphore and blocks until the next "nod". It's as simple as that. > > you'd probably want to go out with using some pthreads library on linux to > create multi-threaded programs. you'll also want to dump the usage of the > semaphore, and use a mutex instead (man pthread_mutex_init). its overhead > is much smaller then that of a semaphore, and it's cleaner to use. > Uhuh. Mutexes and Muxwaits are familiar territory; I didn't want to muddy the water with too much "foreign" stuff. > > I naturally asked myself how would I do that under Linux. And further, how > > would I do it for two or three threads. All this is not academic, since I'll > > almost certainly have to provide a Unix (AIX) port in a few months, but > > development under Linux. > > (my usuall plug:) i'd suggest you check out my multi-threaded programming > tutorial at http://www.actcom.co.il/~choo/lupg/tutorials/ (choose the > multi-threaded programming from the list) to get a feeling regarding > programming with pthreads. there are also various books about this subject Will do. Thanks. > - check on amazon.com or bookpool.com for more info. I have my eye on two items, referred to by Stevens. > > > > Here is another one: A few years back I did a citrus packing house production > > line control system. > > I did the job under OS/2 because Windoze couldn't handle the real time stuff. > > It used 3 processes, one multithreaded with event semaphores and timers all > > over the place. Again, I'm asking myself, how if at all,I would go about that > > sort of thing under Linux. > > by default, unix's timers are NOT real-time. however, there are extentions > for linux that add some real-time support (including real time > scheduling). i think that reading the man pages of 'sched_setscheduler' > for information about setting scheduling policies, and references to > other relevant manual pages. > First, as long as you don't need resolution below a clock tick (~32ms), you don't need anythingspecial. ("100 ms is a lifetime on a Pentium II"). I'll look anyway. I've also come across a real time library for Linux, at http://rtlinux.cs.nmt.edu/~rtlinux/. > > So, why do I care how it's done: The way you use clone() as compared toOS/2 > > _beginthread() influences programme design. Let me make it even messier: How > > do you want to spin off a thread with visual objects in a X-Motif app? I do it > > under OS/2 PM with _beginthread() and it's far from plain sailing. > > don't use clone() directly. if you use any pthreads library, it'll call > clone() for you, and this will make your program (more or less) portabl > across various POSIX conforming OSes (i.e. most modern unices). > > as for X-Motif, you need to make sure that you have thread-safe libraries > (especially a thread-safe Xlib library). If not, then your only work > around is to make sure that only a single thread accesses any X functions > at a given time (e.g. by using a mutex to protect accesses to X funcitons, > or by making all calls to X functions be done from a single thread only). > > note: i haven't yet tried writing a multi-threaded X program, so i don't > have real experience with that. > > hope this helps, > > guy Interesting stuff. Keep in touch!
begin: vcard fn: Daniel Feiglin n: Feiglin;Daniel org: Dilog Computers Ltd. adr: POB 36;;;Shavei Shomron, Mobile Post;;44858;ISRAEL email;internet: [EMAIL PROTECTED] tel;work: 972 9 861 6204 tel;fax: 972 9 862 1052 tel;home: 972 9 832 0939 x-mozilla-cpt: ;0 x-mozilla-html: FALSE version: 2.1 end: vcard