Software :: Posix Semaphores Posting For More Than One Thread At A Time?
Apr 12, 2011I would like to know can we post more than one thread at a time.I have code like below
Code:
#include <stdio.h>
#include <unistd.h>
[code]...
I would like to know can we post more than one thread at a time.I have code like below
Code:
#include <stdio.h>
#include <unistd.h>
[code]...
Rather than get in hot (or even slightly-above-comfortable temperature) water for reviving a closed (ca. 2007) thread without moderator permission or acquaintance of the OP personally or by proxy, I'll post this alternate solution (approach?) along with one positive real-world example illustrating how mine is easier to write and is equally reliable, if not altogether better. The thread is here. Their solution:
Code:
if [ "$myfilesize" eq "0" ];then echo "$file: the file size is zero"; else echo "$file: the file size is NOT zero"; fi (and this hangs on the output of a stat -c %s command). "Hangs" is probably a most appropriate word. The two outputs, using two different stat options, the same file, and three marginally-different command-line syntaxes I just tried gave me these: First, using their approach, I got this:
Code:
tjsfa070929-094.jpg.error: the file size is NOT zero
Even though stat gave me this
Code:
>> stat -c %s $file
[Code]...
From where I sit, getting the file type string instead of an integer, which can be equally (if not often more) accurate, makes for an easier time of setting the conditional and, maybe only in terms of a few ticks, a faster script from start to finish. I think my method is better, and proven so to the limits of my knowledge and ability here in this OP.
i'm trying to understand the POSIX threads and i can't understand when does the thread start: does it start when i do
pthread_create()
or when i do
pthread_join()
or maybe i'm missing something. i do understand that pthread_join() causes the calling thread to wait till the called thread is finished.
I'm running the following code to initiate semaphores:
Code:
int init_semaphore(key_t semkey, int nsems)
{
[code]...
I am going to use "pthread_setaffinity_np" to bind a thread to a specific core. My application has two threads. I have used mutex to assign a specific id to each thread and then bind that thread to a core different from another core. but it seems that the os assigns both thread to one core.What should I do to bind each thread to a specific core?
View 4 Replies View Relatedi'm writting a program, that creates semaphores and shared memory. It asks from the user to give anything to write in the shared memory. Now, i want this program to do this,not only once, but repeat, and stop as soon as the user gives the word "quit". i added a while loop, but i don't know how to stop the program.
View 13 Replies View RelatedI haven't ever had this working as I've never tried before today. Gwibber won't post to my ping.fm account. I'm certain the correct username and web-key have been entered (though Gwibber doesn't tell you one way or the other). It doesn't matter if I try to post via the Gwibber interface or the indicator-applet-session textbox... neither work. No error messages.
- I know Gwibber is working because it will post to twitter, facebook, identica, etc.
- I know my ping.fm account is working because it will post direct from website and/or browser extension
Ok chaps, what do I need similar to Irfan View on T'other OS (hiss) to edit the Size of Photo's, friends tend to get miffed if I email 5MB Pic's. Loads of viewers etc on Ubuntu, like Playing Hopscotch in a Minefield, can give you a really Crap Day!
View 3 Replies View RelatedI have a few small lists created in mailman, and I want users to be able to receive, but not post. Where do you find this setting?
View 2 Replies View RelatedEverything looks like the same, port 110 is also open and accessible, the posting account got email, but never showed up in WordPress, why?
View 2 Replies View RelatedIt seems strange to me that there are so few newsreader programs for Linux that are good for posting binaries, if they do it at all. For a community with such an ethos of sharing, there sure are a lot of "grab"-only newsreaders!
I have used newspost a lot in the past, but I encounter fatal errors when connecting through stunnel, as I now tend to do, and development seems to be dead with that program. Can anyone recommend any other program - console, X, whatever - that will post multipart binary files?
having problem dealing with gnome-do, before this, I never have problem while tweeting with the tweeter plugin in gnome-do.Now, when I want to tweet up with gnome-do, the gnome-do suddenly crash and I need to open it back via Application to make it use back again.
View 4 Replies View RelatedI am trying to compile splasutis in my debian wheezy. ./configure run well, but during make I get the following error
make --silent all-recursive
Making all in libs
CONF libjpeg.a
[code]....
I found out from here that it is not enable URL...I ran the command mount | grep "shm" and got.none on /dev/shm type tmpfs (rw,nosuid,nodev)So how do I enable it?It is need for my ATI graphic card.
View 2 Replies View RelatedIs it possible to add support for POSIX Trace to my Ubuntu?
# getconf _POSIX_VERSION
200809
# getconf _POSIX_TRACE
undefined
How to set you distro to be a POSIX compliant?
View 3 Replies View Relateduse phpldapadmin can add ou,but can not add posix group.following is software version
[root@localhost config]# rpm -qa | egrep '(ldap|db4)'
openldap-devel-2.3.27-8.el5_1.3
db4-utils-4.3.29-9.fc6
[code]....
I have 2 threads and both of them are deleting memory at the end nedded by both.
My problem is that maybe it can happen that a thread start and finish before the other one starts and so it deletes the memory nedded by the other thread. How can I synchronize them so that this can't happend.
As a design my threads look like this:
Code:
The other thread looks the same, but this isn't unoff to stop thread1 to finish before thread2 starts.
It is known that binaries with the SetUID bit enabled are a threat for the system.I saw on this ArchLinux wiki[URL].tead_Of_Setuida way to limit the use of SetUID bit thanks to POSIX capabilities.It looks very interesting.Does anyone of you used it already?Is it a burden for the system afterwards (like binaries not working, needing to be fixed); or is it seamless
View 3 Replies View RelatedI've implemented a program URL... which reads digital IF data from a radio receiver through a named pipe, measures power levels, and sends the result to stdout. The program is interactive; there is a thread that reads from stdin to watch for commands, a thread that constantly either reads data from the named pipe or throws data away, and an array of processing threads. The program uses GTK+extra to plot the signals. The IF data stream bandwidth exists at the limits of today's technology (is very very fast).
Problem Statement:The program works fine with a few bugs. I've learned since I've made it that using global state variables to coordinate threads isn't a good way of doing it. I also only had knowledge of mutexes and polled the state variable instead of using other methods.My reimplementation will use the following:
- One "Stdin Command Monitoring" thread
- One "Get data from named pipe" thread
- One post-processor thread
- N Processing threads
All threads are alive during the life of main()There are N buffers. Data will come in from the named pipe, and the "Get data" thread will write the data to an "available" buffer. When the buffer is full it will be marked as "full". There will be N processing threads, one for each buffer. When a processing threads' buffer is full, it will process the buffer and save the result to a final buffer. At the end of a number of averages, the post-processor thread will perform a final process on the final buffer and send the results to stdout.
All my LC environment variables are currently set to POSIX at boot, though I can't find the startup script that does this. I've grepped through /etc/rcS.d and /etc/rc2.d but no luck. In /etc/default/locale, LANG is set to en_GB.UTF-8, which is my preferred locale. But this doesn't stop all the LC's being set to POSIX. Consequently, my dates follow the American convention, which I find hard to read.
I tried resetting with update-locale LC_TIME=en_GB.UTF-8. This changed all the locales to en_GB but only for the session. When I rebooted, everything went back to POSIX. The only change is that en_GB.utf-8 is now in the /etc/default/locale file as the value of LC_TIME as well as LANG.
I have a pthread waiting forever on a POSIX message queue and then call mq_close and mq_unlink on the POSIX message queue. I've found that the pthread never wakes up from it's call to mq_receive and remains blocked indefinitely. Is there a way to wakeup all pthreads blocked on a POSIX message queue after calling mq_close/mq_unlink? The goal is to include error handling during message queue deletion to avoid leaving any pthreads blocked forever.
View 2 Replies View RelatedI want to add some users to multiple groups. syntax of the file to pass to ldapadd? or would I use lapmodify? Does one add/modify a user record to specify the groups that user is a member of? Or does one add/modify each group record to specify which users are members?
View 1 Replies View RelatedI'm in the process of writing a program that is a server- it will accept connections and stuff, and spawn a child process for each. However, i've run into a small problem. I do NOT want to bother with keeping track of the processes unless i need to. So, i set SA_NOCLDWAIT (#ifdef) on a SIG_IGN to the SIGCHLD handler through sigaction interface. The standard says that it the kernel will then keep track of reaping zombie processes for me (a HUGE plus). However, upon receiving a SIGINT signal, i want to stop the server from accepting new connections (done), and then wait for there to be no new connections. I was thinking of just putting a loop like so:
Code:
while((wait(NULL) != (pid_t)-1) && errno != ECHILD);
However, I'm not *sure* that this will work, especially with SIGCHLD still ignored. So how can i tell if there are still child processes? I can't find any call like int getnumchld(pid_t proc); (i wish). Plus it would be inefficient to spin on that function anyway. OTOH, i would rather *NOT* have to do the same thing in a loop with a system("ps |...>file"); read(file); etc. either. Is there a way i can portably implement this feature (I was hoping i could run it on linux and the major BSDs, at least).
TO SUM IT UP:
How can i tell if a process has no child processes if i've SIG_IGN'd SA_NOCLDWAIT'd the SIGCHLD? Is there a _reasonably_ portable way to do so? I *don't* want to manually wait for EVERY process. Maybe only those still active at the time of SIGTERM, but that requires keeping track of the number of connections and whether those have terminated...
EDIT: Does anyone know if the above code *would* work, even with SIGCHLD ignored and the kernel cleaning up zombies *for* me? I checked the manpage and it doesn't say much.
EDIT1: Note that all of the processes are in the same process group and session. SO i can find them through this as well. Perhaps even setting the uid/gid and finding all processes run by that group?
EDIT2: i have an idea if the above isn't feasible. If there is no "elegant" way to do it, i could reduce the complexity by sending a SIGUSR1 to the whole process group. Each process would then set a flag telling it to send a SIGUSR1 in reply and send a SIGUSR2 when it is done executing. Then i could keep a count of signals. Maybe that would be *easier*. Or perhaps a count of all child processes and just a termination signal to decrement the counter.
I want to communicate between two threads, each belonging to a different process. Iam using message queues for this. I use mq_open()call. I created the queues with the same queue name starting with a '/'. But when I open the queue, the queue ID is different in both the process. What should I do so that both the process have the same queue ID?
View 1 Replies View RelatedI have created two threads:
Thread 1 and thread 2
In the main thread, i have put up a timer which generates a signal periodically when it expires, which reults in execution going to signal catcher function.when this function is invoked, under certain condition it goes to thread 1 and under another condition it goes to thread 2. The problem lies here that when it goes to thread2,i have a loop to process but it doesnt come out of the loop and hence from thread2, even though timer has expired.
In a single main() function,so need signal handling. Use Posix Message Queue IPC mechanism , can ignore the priority and other linked list message,to implement the scenario:
View 1 Replies View RelatedWhen posting results from ifconfig, it shows the hardware address of etho, etc. Would you consider that to be a security risk ?
View 9 Replies View RelatedWhat is the quickest way to get the thread id(tid) of the current thread in linux? Specifically I use fedora 13. ...and I am talking about inside a C++ program.
View 2 Replies View RelatedIs there a library/system call that will return to me what CPU core a thread of execution is running on? I've looked for a bit on the net already and also in /usr/include and couldn't find one.
getcpu() and sched_getcpu() are two that I found, but when I include the appropriate header files (linux/getcpu.h, and sys/sched.h respectively), gcc says getcpu.h doesn't exist and the linker complains it cannot find the implementation in sched.h.
I'm sure I'm doing something really stupid or overthinking...
What I am doing is running an OpenMP application and specifying a list of cpu cores to run on with GOMP_CPU_AFFINITY. I want to make sure that each core is getting the same number of threads.
**UPDATE**
It seems that this code works, but only with glibc >= 2.6, and my machine has 2.5:
Code:
#define _GNU_SOURCE
#include <stdio.h>
#include <utmpx.h>
int main( void )
[Code].....