SVP g besoin d'aide

Résolu
hero01 Messages postés 12 Date d'inscription dimanche 13 août 2006 Statut Membre Dernière intervention 9 avril 2009 - 31 janv. 2008 à 13:46
hero01 Messages postés 12 Date d'inscription dimanche 13 août 2006 Statut Membre Dernière intervention 9 avril 2009 - 31 janv. 2008 à 14:01
Un
tableau t de 2N nombres entiers est situé en mémoire partagée. On souhaite
regrouper dans la première moitié du tableau les N plus petits éléments et dans
la seconde moitié les N plus grands. Pour résoudre ce problème, on se propose
d'utiliser deux processus (père/fils) : l'un (dans notre réalisation le père)
recherche le plus grand élément de la première moitié du tableau et le second
(ici le fils) recherche le plus petit élément de la seconde moitié du tableau.
Lorsque les deux processus ont terminé cette recherche, la comparaison de ces
minimums et maximums relatifs permet à l'un des deux (ici le fils) de décider
de l'échange des deux éléments : l'échange aura lieu si le plus grand élément
de la partie gauche est plus grand que le plus petit de la partie droite.
L'intérêt de choisir ici le fils est que si le fils détecte qu'il n'y a pas à
effectuer et se termine, le processus père sera averti de la terminaison du
travail. Les deux processus doivent par ailleurs se synchroniser sur la fin de
la phase de recherche de minimum et maximum que chacun accomplit et un
mécanisme doit permettre au père de savoir s'il doit ou non itérer la phase
précédente. La solution que vous devez adopter utilise un ensemble de deux
sémaphores : le second permet au processus fils d'indiquer au processus père
qu'il a effectué, si cela est nécessaire l'échange des éléments maximal et
minimal des deux moitiés du tableau.

2 réponses

hero01 Messages postés 12 Date d'inscription dimanche 13 août 2006 Statut Membre Dernière intervention 9 avril 2009
31 janv. 2008 à 13:53
   Je dois utiliser java Threads mais vu mais conaissance limitté en java je vous pris de m'aider si c possible les amis.
3
hero01 Messages postés 12 Date d'inscription dimanche 13 août 2006 Statut Membre Dernière intervention 9 avril 2009
31 janv. 2008 à 14:01
Voila un debut mais je ne vois pas cmt faire pour crée 1 tableau et faire comuniqué les processus pere et fils
--------------------------------------------------------------------
import
[javascript:searchRef('java') java].[javascript:searchRef('io') io].[javascript:searchRef('Serializable') Serializable];
import[javascript:searchRef('java') java].[javascript:searchRef('util') util].*;

import[javascript:searchRef('org') org].[javascript:searchRef('rcosjava') rcosjava].[javascript:searchRef('hardware') hardware].[javascript:searchRef('memory') memory].[javascript:searchRef('Memory') Memory];

/**
* A basic shared memory class allowing the IPC manager to handle processes
* reading and writing the same block of memory.
*
* <DT> History:
* <DD> 11/08/98 Improved implementation. AN </DD>
* <DD> 13/08/98 Write return old value on success. AN </DD> </DT>
*
* @author Bruce Jamieson.
* @author Andrew Newman.
* @created 30th March 1996
* @version 1.00 $Date: 2003/02/23 12:27:55 $
*/
publicclass[javascript:searchRef('SharedMemory') SharedMemory]implements[javascript:searchRef('Serializable') Serializable]
{
/**
* A list of all the processes with open connections to this memory block.
*/
private[javascript:searchRef('List') List][javascript:searchRef('processConnections') processConnections] = new[javascript:searchRef('ArrayList') ArrayList]();

/**
* The numerical identifier of this block.
*/
privateint[javascript:searchRef('sharedMemoryId') sharedMemoryId];

/**
* The shared memory block size.
*/
privateint[javascript:searchRef('size') size];

/**
* The string identifier of this block.
*/
private[javascript:searchRef('String') String][javascript:searchRef('name') name];

/**
* The process that first created the shared memory segment.
*/
privateint[javascript:searchRef('originalProcessId') originalProcessId];

/**
* Create a new shared memory object.
*
* @param newName the unique name of the shared memory block.
* @param newSharedMemoryId the unique numerical identifier.
* @param newOriginalProcessId the process that created this block.
* @param newSize the size of the shared memory block.
*/
public[javascript:searchRef('SharedMemory') SharedMemory]([javascript:searchRef('String') String][javascript:searchRef('newName') newName], int[javascript:searchRef('newSharedMemoryId') newSharedMemoryId],
int[javascript:searchRef('newOriginalProcessId') newOriginalProcessId], int[javascript:searchRef('newSize') newSize])
{
[javascript:searchRef('name') name] = [javascript:searchRef('newName') newName];
[javascript:searchRef('sharedMemoryId') sharedMemoryId] = [javascript:searchRef('newSharedMemoryId') newSharedMemoryId];
[javascript:searchRef('originalProcessId') originalProcessId] = [javascript:searchRef('newOriginalProcessId') newOriginalProcessId];

// Connect the creating process to this memory block
[javascript:searchRef('open') open]([javascript:searchRef('newOriginalProcessId') newOriginalProcessId]);
[javascript:searchRef('size') size] = [javascript:searchRef('newSize') newSize];

// Assume Higher level will detect duplicate Shrm Segs
// (aID) and return error - not to be done here?
}

/**
* Returns the id of the shared memory.
*
* @return the id of the shared memory.
*/
publicint[javascript:searchRef('getSharedMemoryId') getSharedMemoryId]()
{
return[javascript:searchRef('sharedMemoryId') sharedMemoryId];
}

/**
* Returns the name of the shared memory.
*
* @return the name of the shared memory.
*/
public[javascript:searchRef('String') String][javascript:searchRef('getName') getName]()
{
return[javascript:searchRef('name') name];
}

/**
* Open a connection from a process to the shared memory.
*
* @param newPID the new process id to connect.
*/
publicvoid[javascript:searchRef('open') open](int[javascript:searchRef('newPID') newPID])
{
[javascript:searchRef('Integer') Integer][javascript:searchRef('pid') pid] = new[javascript:searchRef('Integer') Integer]([javascript:searchRef('newPID') newPID]);
[javascript:searchRef('processConnections') processConnections].[javascript:searchRef('add') add]([javascript:searchRef('pid') pid]);
}

/**
* Close a connection to a process to the shared memory.
*
* @param existingPID the process to disconnect from.
* @return Description of the Returned Value
*/
publicint[javascript:searchRef('close') close](int[javascript:searchRef('existingPID') existingPID])
{
[javascript:searchRef('Integer') Integer][javascript:searchRef('pid') pid] = new[javascript:searchRef('Integer') Integer]([javascript:searchRef('existingPID') existingPID]);
[javascript:searchRef('processConnections') processConnections].[javascript:searchRef('remove') remove]([javascript:searchRef('pid') pid]);

// IF there are no connections open to the sem, then the
// sem should die..
// Do this by returning the number connected
// (Let someone else deal with the problem..)
return[javascript:searchRef('processConnections') processConnections].[javascript:searchRef('size') size]();
}

/**
* Returns the number of bytes that the memory segment is.
*
* @return the number of bytes that the memory segment is.
*/
publicint[javascript:searchRef('size') size]()
{
return[javascript:searchRef('size') size];
}

/**
* Returns the creator of the shared memory segments process id.
*
* @return the creator of the shared memory segments process id.
*/
publicint[javascript:searchRef('getProcessId') getProcessId]()
{
return[javascript:searchRef('originalProcessId') originalProcessId];
}
}
3
Rejoignez-nous