how to implement the function getmsgwait() from memory queue?

  • Permalink
  • submit to reddit
  • Email
  • Follow


Hi there,

I made a shared memory queue, and i implemented the function getmsg() from
the queue.

the function getmsg() works like this

getmsg()
{
lock the queue
check the stored count
read the stored item
unlock the queue
}

if there is no stored item, i have to call getmsg() function continuously.
i don't like this.
i would like to make function, getmsgwait(int waittime) which can wait until
some item is stored in the queue or waittime expires.

Would anyone like to tell me how to implement it

Thanks in advance,

Jaguk Ku


0
Reply Jaguk 9/7/2004 12:42:49 PM

See related articles to this posting


Jaguk Ku wrote:
> Hi there,
> 
> I made a shared memory queue, and i implemented the function getmsg() from
> the queue.
> 
> the function getmsg() works like this
> 
> getmsg()
> {
> lock the queue
> check the stored count
> read the stored item
> unlock the queue
> }
> 
> if there is no stored item, i have to call getmsg() function continuously.
> i don't like this.
> i would like to make function, getmsgwait(int waittime) which can wait until
> some item is stored in the queue or waittime expires.
> 
> Would anyone like to tell me how to implement it

use condition variables and broadcast insertion of a new item into the queue.
in posix world, it's pthread_cond_init(3)/pthread_cond_broadcast(3).
Use pthread_cond_timedwait(3) to implement waittime.

-- 
Lev Walkin
vlm@lionet.info
0
Reply Lev 9/7/2004 1:13:46 PM

Jaguk Ku wrote:

> Hi there,
> 
> I made a shared memory queue, and i implemented the function getmsg() from
> the queue.
> 
> the function getmsg() works like this
> 
> getmsg()
> {
> lock the queue
> check the stored count
> read the stored item
> unlock the queue
> }
> 
> if there is no stored item, i have to call getmsg() function continuously.
> i don't like this.
> i would like to make function, getmsgwait(int waittime) which can wait until
> some item is stored in the queue or waittime expires.
> 
> Would anyone like to tell me how to implement it

I did just that of I understand you correctly, you can probably use this;
http://utelsystems.dyndns.org/code/threadqueue/
0
Reply ISO 9/7/2004 1:33:07 PM

Jaguk Ku wrote:
> Hi there,
> 
> I made a shared memory queue, and i implemented the function getmsg() from
> the queue.
> 
> the function getmsg() works like this
> 
> getmsg()
> {
> lock the queue
> check the stored count
> read the stored item
> unlock the queue
> }
> 
> if there is no stored item, i have to call getmsg() function continuously.
> i don't like this.
> i would like to make function, getmsgwait(int waittime) which can wait until
> some item is stored in the queue or waittime expires.
> 
> Would anyone like to tell me how to implement it

One way would be to create a semaphore (man semop, semctl and semget 
also intro(2)).  Writers increment it, readers decrement it.  Readers 
can block on it until it is > 0.

-- ced

> 
> Thanks in advance,
> 
> Jaguk Ku
> 
> 


-- 
Chuck Dillon
Senior Software Engineer
NimbleGen Systems Inc.
0
Reply Chuck 9/7/2004 1:51:36 PM

Nils O. Sel�sdal wrote:

>> I made a shared memory queue, and i implemented the function getmsg() 
>> from
>> the queue.
>>
>> the function getmsg() works like this
>>
>> getmsg()
>> {
>> lock the queue
>> check the stored count
>> read the stored item
>> unlock the queue
>> }
>>
>> if there is no stored item, i have to call getmsg() function 
>> continuously.
>> i don't like this.
>> i would like to make function, getmsgwait(int waittime) which can wait 
>> until
>> some item is stored in the queue or waittime expires.
>>
>> Would anyone like to tell me how to implement it
> 
> 
> I did just that of I understand you correctly, you can probably use this;
> http://utelsystems.dyndns.org/code/threadqueue/

On second thought, i perhaps did not understand you. The above is for
threads only. Not between processes. If you need that, semaphores
might be what you need. man semop,semctl,semget.
0
Reply ISO 9/7/2004 1:57:47 PM
comp.unix.programmer 10676 articles. 64 followers. Post

4 Replies
224 Views

Similar Articles

[PageSpeed] 59


  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

implement a queue as shared memory
I am trying to figure out how to implement a queue using shared memory. I want to do this so 2 threads can access this queue, but with mutual exclusion. say I wanted a queue of max size 5 integers int seg_id = shmget(IPC_PRIVATE, 20480, S_IRUSR | S_WRUSR); //this gets my shared memory but how do I make this shared memory a queue? could I do this: queue<int> *shared_queue; shared_queue = (int *) shmat(seg_id, NULL, 0); would this work? would this allow me to still use the common queue functions like pop, push, front? am I way off on this? Leshanster <leshanster@gmail.com>...

how to implement a queue-like container with sort function
I want to a fixed length list-like container, it should have a sorted()-lik= e function that I can use to sort it,I think there should also a function I= can use it to detect whether the numbers of items in it reaches the length= of the container , because if the numbers of items in it reaches the lengt= h(fixed) of the container,I want to process the data in it .Is there a cont= ainer in Python like this ?If not, what base container should be used to im= plement such container? the container is similar to queue ,but queue doesn't have a sort function= =20 On Fri, Nov 29, 20...

Internal of C/C++ run time library (Module offers a function that allocates memory, must also offer a function that frees memory)??
Single address space consists of one executable module and several DLL modules. Some of these modules can link to a static version of the C/C + + run-time library, some of these modules might link to a DLL version of the C/C++ run-time library, and some of these modules (if not written in C/C++) might not require the C/C++ run-time library at all. Please put some light on how C/C++ runtime library malloc or free functions works in a address space and how static linking or dynamic linking can affect the allocation or deallocation of a memory in a single address space. Thanks in a...

call a function within a (function() {...})(); implementation
How do you call a function within an implementation that's in this form: (function () { var G_vmlCanvasManager_ = { init: function() { ... }, initElement: function (el) { ... } ... })(); I'm trying to call the initElement function that's within excanvas.js which its comment says is public. If I try calling initElement(c) or G_vmlCanvasManager_.initElement(c) IE gives errors. Andrew Poulos Ok, I missed the externs at the bottom of the library and the version of excanvas I was using did not return the element when you initialised a new element....

Out of memory & Function MEMORY is not available on this platform
well guys is very strange... since: when I type: help memory I am to get response from Matlab as: .... Example 1: Run the MEMORY command on a 32-bit Windows system: .... Example 2: Run the MEMORY command on a 64-bit Windows system: .... Example 3: Run the MEMORY command with two outputs on a 32-bit Windows system: [uV sV] = memory .... but when I type: memory ??? Error using ==> memory Function MEMORY is not available on this platform. Its kind of strange isn't it? btw I use MAC OS X 10.6 (might this be a problem?) Moreover I would like to execute this ...

implementation of rotation function without built-in function
i am given a task for rotating the image without using imrotate function, i am using affine function for the task. this is what i have done deg=75; orignal_img = imread('path of the image'); [row col]= size(orignal_img); affinematrix=[cos(deg) sin(deg) 0; -sin(deg) cos(deg) 0; 0 0 1]; for x=1:row for y=1:col rot(x*y)=orignal_img(x*y)*affinematrix; end end as i am doing pixel by pixel rotation, i don't get the logic of the error ??? Error using ==> times Class of operand is not supported. can anyone please guide me that what is missing...

How memory function free() knows how much memory to free.
Hi, How does the memory management function 'free()' frees the memory pointed by a pointer variable at run time. how does it know the size. if there is way when free() can do, then why can't we do it externally?. Thanks Panduranga Chary > Hi, > > How does the memory management function 'free()' frees the memory > pointed by a pointer variable at run time. how does it know the size. > if there is way when free() can do, then why can't we do it > externally?. When you malloc memory, the size of the allocated block is stored somewhere. What do you...

Implementing an STL memory pool with constant memory locations
I'm asking for a lot here but what I would like to do is create a dynamically growing memory pool whose addresses don't change. I understand I can't do this with std::vector so for the explanation I'll use an imaginary class called pool. What I mean: pool.push_back(object); // Increases memory size by a block size, say 10 elements After 10 push_back's pool.push_back(object); // APPEND 10 additional memory block sizes BUT elements 1 thru 10 retain their memory locations. What I'm trying to do: I am trying to use a tree whose elements maintain a key and a pointer t...

virtual function and pure virtual function in the implementation of COM
Hello All, Please excuse me for posting this here, but I don't find any other group where I will get a proper answer. This is about clarifying the C++ part of COM. I understand that COM is a mechanism by which interface and implementation is seperated. A basic com implementation in c++ can be as follows. // Dev-CPP // interface // Ai.h class Ai { public: virtual void foo() = 0; virtual Ai* GetInterface() =0; }; // Implementation // A.h #include "Ai.h" class AImpl : public Ai { public: void foo(); Ai* GetInterface(); }; // A.cpp #include "A.h&qu...

Calling functions from functions from functions ...
Lets say I have a function g(p,x) where x and p are of some defined type. I also have a function NewtonR which I can use like so: x = NewtonR(g,p,x0) There is also another function I want to call ImplicitTrap which can be done as: u = ImplicitTrap(g,p,u0,step,n) This function defines a function of g, and it is this function that I'd like to pass to NewtonR. Can it be done? Basically the code is implementing the implicit trapezoidal rule for numerical integration with the NR solver being used at each step with automatic differentiation being used to handle the differentiation. M...

To Queue or Not To Queue
Hi I have a number of Queue groups defined which are working as expected. Is it possible to produce a hack to cause some messages to always queue and some to be processed normally? Preferably based on the access map. cheers Matt On 01/14/07 16:52, matt.hampton.uk@gmail.com wrote: > Is it possible to produce a hack to cause some messages to always queue > and some to be processed normally? Preferably based on the access map. I'm not sure if it will provide what you are after or not. You may want to consider looking in to Sendmail's quarantining capability. That is to...

When is a function not a function?
I've got a collection of functions that accept a function or object (paired with a method name) as a callback. For the longest time I have relied on this test. (typeof cb == 'function') This should work as well, but I am not sure how well it degrades in older browsers. I think there are issues with functions created in another context (eg frame) as well. (cb instanceof Function) Then I came across this. (!!fn && typeof fn != "string" && !fn.nodeName && fn.constructor != Array && /function/i.test( fn + "" )) I'm sure it...

Function functionality
Hey, I&#8217;m sure this is something that is relatively easy to code for, but I haven&#8217;t been able to do it easily without generating lots of different error messages! Basically, I created an M-file, let&#8217;s say it&#8217;s called Batch_Run, and I want it&#8217;s operation to differ depending on what the user types in the command window. For example, currently, if the user types &#8216;Batch_Run&#8217; in the command window, MatLab processes ALL the files in the current directory using the code in the M-file. However, I would also like it so that if the use...

function of a function
Tried to solve numerically: http://groups.google.com/group/sci.math/browse_frm/thread/248f76d024c1ac57/0bba983777a07bc9#0bba983777a07bc9 thus: EQ= { f'[x] == f[f[x]], f[0]== 1} ; NDSolve[EQ,f,{x,0,2}]; But gives an error. NDSolve::ndnum: Differential equation does not evaluate to a number at x = 0. Also does not work even with other f[0] values. Any way to do that? Hi, it can't work because f[0]==1 give in your differential equation f'[0]==f[1] and NDSolve[] can't find the value for f[1] until it has integrated the equation. The neted dependence...

function implementation
Hi all, C comes with standard libraries. Let say I am interested in one function called strlen from string.h. And here is the declaration (http://www.acm.uiuc.edu/webmonkeys/book/c_guide/): Declaration: size_t strlen(const char *str); Computes the length of the string str up to but not including the terminating null character. Returns the number of characters in the string. My question is: is it possible for me to read its definition or to know how this function is implemented? Thanks, Li chen_li3@yahoo.com said: > Hi all, > > C comes with standard libraries. Let say I ...

function implementation
Hi I am trying to code the following function in matlab, V = ( B/(k-1) ) / (W / (N-k)) ; B is sum squares between U # of vectors (unknown) W is sum of squares between L # of vectors (unknown) k - number of clusters (known) N - number of vectors (known) "Al B" <bourisly@gmail.com> wrote in message <gkqoh1$rat$1@fred.mathworks.com>... > Hi I am trying to code the following function in matlab, > > V = ( B/(k-1) ) / (W / (N-k)) ; > > B is sum squares between U # of vectors (unknown) > W is sum of squares between L # of vectors (unknown) > > k -...

Function with a function
I have a GUI that calls a separate function (a different m-file) to perform a certain task. Since this task takes several minutes to complete, I would like to place some frames on the GUI to show progress as the second function runs. These frames would change colors upon getting to certain stages of the code. I am able to get the frames to change color but they do so only after the second function is finished running. Obviously this is no good. A sample of my code is as follows: set(findobj('Tag',['frame2']),'BackgroundColor','green'); This code is contained w...

implementation of $() functionality
Hello I want to implement the following functionality. (It might be a bit similar to the implementation of $() functionality of scripting languages.) Suppose I have a string - generated or inputted. I want my program to invoke a function of the same name. Obviously, I can do this with an if-else ladder. However, that would be really poor implementation when the number of the strings is large. (It might be something like dynamically invoking the compiler.) Thank you Cross On Jun 12, 8:16=A0am, Cross <X...@X.tv> wrote: > Suppose I have a string - generated or inputted. I want my pro...

Functions of Functions
Hello, I was wondering if anyone could help me with this. I've gone through the book and help files as best I can, but can't seem to figure out why the following doesn't work: I'm trying to work with functions that take functions as parameters and return other functions. Below is an example... (*clear stuff*) Clear[a, b, c, x] (*Define a functions a*) \!\(a[x_] := \((Sin[x] + x\^3\/2)\)\) (*define a function of functions*) \!\(b[f_] = \((f'' + \(3\ f'\)\/2 + 5 f)\)\) (*apply the functional function to a*) c = b[...

function of a function!!
maybe i hasn't well formulated my question before, so my question is: I have a function f = f(g) where g = g(a,b) is another function, i need, in the function f to use a parameter of the function g (let's say a), is there a way to call the parameter a inside the function f?? thanks In article <ef11409.-1@webx.raydaftYaTP>, rafi <mimosi1@hotmail.com> wrote: > maybe i hasn't well formulated my question before, so my question is: > > I have a function f = f(g) where g = g(a,b) is another function, i > need, in the function f to use a parameter of the func...

To queue or not to queue
Hey group, I recently started a new job where the target is a handheld device with 3 buttons on it and a few other internal interrupts, occurring maybe only every 125ms when it is in a real processing mode, with little processing to do to service the interrupts. The system runs on a low power controller and goes to low power mode whenever possible. It is implemented as a state machine, with a bunch of sub-states, so it is really a single threaded application. This was initially designed and implemented maybe 20 yrs ago, and ported over the years. But, the exisiting design has an event queue....

function to function
Hi friends .. Is it possible to set the parameters in a function with a different function..? If yes can you please a sample to erguzel2000@yahoo.com ...

Implementing function handles when compiling GUI-based callback functions
I am having issues trying to compile a program with graphics created in the Matlab GUI development environment. I created the program and then tried to compile it using the Visual Studio Matlab Add-in. The first graphic screen comes up, but when I press on a button or perform any action that calls a new m-file, I get errors in the run-time executable screen. I called Matlab and they told me I had to implement function handles to call/execute a new m-file in the program, but there is limited documentation for this. I can't seem to figure out how to implement this properly. Has...

functions function
The 'functions' function has changed in R14. Further it's help text is misleading. Why would this be a good idea? This was a very useful function. Is there alternative efficient way of obtaining the parent file from a function handle? The help is misleading because it suggests that f = functions(@deblank) f = function: 'deblank' type: 'overloaded' file: 'matlabroot\toolbox\matlab\strfun\deblank.m' methods: [1x1 struct] when what you really get is, >> f = functions(@deblank) f =...